Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging and docker support #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
venv
36 changes: 36 additions & 0 deletions .github/workflows/my-sync-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
schedule:
- cron: '0 7 * * 1,4'
# scheduled at 07:00 every Monday and Thursday

jobs:
sync_with_upstream:
runs-on: ubuntu-latest
name: Sync master with upstream latest

steps:
# Step 1: run a standard checkout action, provided by github
- name: Checkout master
uses: actions/checkout@v2
with:
ref: master
# submodules: 'recursive' ### possibly needed in your situation

# Step 2: run this sync action - specify the upstream repo, upstream branch to sync with, and target sync branch
- name: Pull (Fast-Forward) upstream changes
id: sync
uses: aormsby/[email protected]
with:
upstream_repository: panr/hugo-theme-hello-friend
upstream_branch: master
target_branch: master
git_pull_args: --ff-only # optional arg use, defaults to simple 'pull'

# Step 3: Display a message if 'sync' step had new commits (simple test)
- name: Check for new commits
if: steps.sync.outputs.has_new_commits
run: echo "There were new commits."

# Step 4: Print a helpful timestamp for your records (not required)
- name: Timestamp
run: date
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
__pycache__/
__pycache__
__pycache__
venv
.vscode
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim-buster

EXPOSE 5000

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED 1

# Install pip requirements
ADD requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
ADD . /app

# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "website_generator.py"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ Go to the [website](https://sampom100.github.io/UnusualVolumeDetector/)

![s9jtygygl0e51](https://user-images.githubusercontent.com/28206070/88943801-8c860a00-d251-11ea-833b-8e7685360ab2.png)

### Docker

Build the docker image using ```docker build```

```
docker build -t unusual-volume-detector:latest .
```

Run the docker image using docker run
```
docker run --rm -d --name unusual_volume_detector -p 5000:5000 unusual-volume-detector:latest
```

The main code take ~ 100 sec to run before the webserver will start.
After that, open [http://localhost:5000](http://localhost:5000) for the webserver.

### Websites

Expand All @@ -36,6 +51,7 @@ Go to the [website](https://sampom100.github.io/UnusualVolumeDetector/)

[alternate credit](https://www.removeddit.com/r/wallstreetbets/comments/i10mif/i_made_a_website_for_that_scanner_made_by_that/)

Or run your own via docker container (above)

### Donations

Expand Down
14 changes: 9 additions & 5 deletions market_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from tqdm import tqdm
from joblib import Parallel, delayed, parallel_backend
import multiprocessing
import logging

logging.basicConfig(filename="main_ouput.log", level=logging.INFO)

###########################
# THIS IS THE MAIN SCRIPT #
Expand Down Expand Up @@ -55,13 +58,13 @@ def find_anomalies(self, data):
return d

def customPrint(self, d, tick):
print("\n\n\n******* " + tick.upper() + " *******")
print("Ticker is: "+tick.upper())
logging.info("\n\n\n******* " + tick.upper() + " *******")
logging.info("Ticker is: "+tick.upper())
for i in range(len(d['Dates'])):
str1 = str(d['Dates'][i])
str2 = str(d['Volume'][i])
print(str1 + " - " + str2)
print("*********************\n\n\n")
logging.info(str1 + " - " + str2)
logging.info("*********************\n\n\n")

def days_between(self, d1, d2):
d1 = datetime.datetime.strptime(d1, "%Y-%m-%d")
Expand Down Expand Up @@ -95,13 +98,14 @@ def main_func(self):
Parallel()(delayed(self.parallel_wrapper)(x, currentDate, positive_scans)
for x in tqdm(list_of_tickers))

print("\n\n\n\n--- this took %s seconds to run ---" %
logging.info("\n\n\n\n--- this took %s seconds to run ---" %
(time.time() - start_time))

return positive_scans


if __name__ == '__main__':
logging.info("Starting main application")
mainObj().main_func()


Expand Down
17 changes: 11 additions & 6 deletions website_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import shutil
import numpy
from market_scanner import mainObj
import logging

logging.basicConfig(filename="web_ouput.log", level=logging.INFO)

# this is used by me AUTOMATICALLY to update the web page you can find at: https://sampom100.github.io/UnusualVolumeDetector/

Expand All @@ -33,16 +36,18 @@ def home():


if __name__ == "__main__":
os.system('git fetch')
# os.system('git fetch')
logging.info("Staring main calculation")
stonk_search = mainObj()
stonks = stonk_search.main_func()
logging.info("Calculation finish")
freezer.freeze()
copyfile('build/index.html', 'index.html')
shutil.rmtree('build/')
# I'm lazy :)
os.system('git add .')
os.system('git commit -m "updated website"')
os.system('git push origin master')
# print(stonks)
# app.run(host='0.0.0.0', port='5000') # run the app on LAN
# os.system('git add .')
# os.system('git commit -m "updated website"')
# os.system('git push origin master')
logging.info(stonks)
app.run(host='0.0.0.0', port='5000') # run the app on LAN
# app.run() # run the app on your machine