Skip to content

Commit

Permalink
added usage case, put run.py in a function
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-pollak committed Feb 17, 2021
1 parent 3800420 commit 4416ed3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 39 deletions.
24 changes: 18 additions & 6 deletions matcher/__main__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import argparse
import sys

parser = argparse.ArgumentParser(description='Run EW matcher or output stats')
parser.add_argument('--run', help='Run the EW matcher', action='store_true')
parser.add_argument('--stats', help='Show stats', action='store_true')
from .run import run_matcher
from .stats import output_profit, plot_bal_time_series_graph
from .output import reset_csv

parser = argparse.ArgumentParser(description='Run EW matcher or output stats',
prog='python3 -m matcher')
parser.add_argument('-r',
'--run',
help='Run the EW matcher',
action='store_true')
parser.add_argument('-s',
'--stats',
help='Display stats and generate graph',
action='store_true')
parser.add_argument('--setup', help='Reset csv', action='store_true')
args = parser.parse_args()

if args.run:
from .run import *
run_matcher()

if args.stats:
from .stats import output_profit, plot_bal_time_series_graph
output_profit()
plot_bal_time_series_graph()

if args.setup:
from .output import reset_csv
reset_csv()

if len(sys.argv) == 1:
parser.print_help()
67 changes: 34 additions & 33 deletions matcher/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,37 @@ def login():
sys.stdout.flush()


print(f'Started at: {datetime.now().strftime("%H:%M:%S %d/%m/%Y")}')
while True:
try:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(
"user-agent=Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36"
)
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--remote-debugging-port=9222") # this
chrome_options.add_argument("--disable-dev-shm-using")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("start-maximized")
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(options=chrome_options)
sys.stdout.flush()
login()
scrape(driver)
except ValueError as e:
sys.stdout.flush()
print('ERROR: %s\n' % e)
except KeyboardInterrupt:
sys.stdout.flush()
print('Exiting')
sys.exit()
except Exception as e:
sys.stdout.flush()
print('Error occured: %s' % e)
print(traceback.format_exc())
finally:
driver.quit()
def run_matcher():
print(f'Started at: {datetime.now().strftime("%H:%M:%S %d/%m/%Y")}')
while True:
try:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(
"user-agent=Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36"
)
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--remote-debugging-port=9222") # this
chrome_options.add_argument("--disable-dev-shm-using")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("start-maximized")
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(options=chrome_options)
sys.stdout.flush()
login()
scrape(driver)
except ValueError as e:
sys.stdout.flush()
print('ERROR: %s\n' % e)
except KeyboardInterrupt:
sys.stdout.flush()
print('Exiting')
sys.exit()
except Exception as e:
sys.stdout.flush()
print('Error occured: %s' % e)
print(traceback.format_exc())
finally:
driver.quit()

0 comments on commit 4416ed3

Please sign in to comment.