-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
141 lines (126 loc) · 5.95 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import signal
import sys
from docopt import docopt
from worker import WebWorker
from multiprocessing import Process
import time
def process_worker(worker_id, _):
worker = WebWorker(is_get_data=True, keep_driver_alive=False)
worker.get_website(worker_id)
def multiple_processes():
p0 = Process(name='p0', target=process_worker, args=('3-0', None))
p1 = Process(name='p1', target=process_worker, args=('3-1', None))
p2 = Process(name='p2', target=process_worker, args=('3-2', None))
p0.start()
time.sleep(2)
p1.start()
time.sleep(2)
p2.start()
def main():
"""Punter command-line interface.
Usage:
cli.py <websites> <leagues> [options]
Options:
--all Get all leagues
--get-only Don't merge and print matches
--print Don't get latest odds, just print out based on saved odds
--print-betfair-only Don't print other results
--send-email-api Send email by MailGun's restful api
--send-email-smtp Send email by SMTP (note: not working in GCE)
--send-email-when-found Send email by api when returns bigger than 99.5
--loop=<n> Repeat every n minutes [default: 0]
--ask-gce=<websites> Read from GCE for these websites
--gce-ip=<ip> GCE instance IP
--bonus Calculate and print bonus profit
--calc-best=<odds> Calculate and print best profit
--calc-back=<odd> Calculate and print real back odd
--highlight=<string> monitor one match
--betfair-limits=<number> highlight when biggest back and lay less than
--betfair including betfair back odds
--exclude=<websites> excluding websites
--compare-one=<website> read urls from <website>.txt, compare with betfair and print
--compare-race read urls from race.txt and compare
--compare read urls from compare.txt which contains many backs and one lay
--compare-multi-process real urls via multiple process
--get-lay-markets get lay markets and store to a temp file
--get-lay-markets-new get lay markets and store to a temp file
--get-urls get urls and write to compare.txt
--test test functionality which underdevelopment
--snr=<odds> calculate SNR profits
Example:
cli.py luxbet,crownbet a
cli.py all eng,uefa
cli.py bet365,ubet fra --ask-gce=bet365 --gce-ip=1.2.3.4 --loop=10
cli.py a a --calc-best=2.10,3.5,3.75
cli.py a a --calc-back=4.2
cli.py bet365 gem "Adelaide Utd,Central Coast,,3.55,1.0" # draw > 3.55 or lost > 1.0
cli.py bet365 eng --betfair-limits=1,2,0.05,-5 # 1 < lay odd < 2, diff <= 0.05, profit > -5
cli.py a a --compare-one=ladbrokes # or: classicbet, william
cli.py a a --snr=1,1.1,5,6.5
"""
worker = False
def signal_handler(_, __):
print('You pressed Ctrl+C!')
if worker and worker.driver:
worker.driver.quit()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
args = docopt(str(main.__doc__))
if args['--compare-multi-process']:
multiple_processes()
elif args['--test']:
WebWorker.calc_4_round_1_back(1.25, 1.18, 1.61, 1.48,
1.29, 1.21, 1.66, 1.55,)
if False: # get q profits
for a in range(30, 40):
print('--- ' + str(a))
for back_odd, lay_odd in zip([a/10]*8, [x * 0.1 for x in range(a-7, a+2)]):
profit = WebWorker.get_q_profit(float(back_odd), float(lay_odd))
print('{:0.1f} {:0.2f} {:0.2f}'.format(float(lay_odd), profit/2, (float(back_odd) / (float(lay_odd) - 0.05) * 50)))
elif args['--snr'] is not None:
odds = args['--snr'].split(',')
for back_odd, lay_odd in zip(odds[::2], odds[1::2]):
profit = WebWorker.get_snr_profit(float(back_odd), float(lay_odd))
print('{:0.2f} back {} lay {}'.format(profit, back_odd, lay_odd))
else:
worker = WebWorker(
is_get_data=not args['--print'] and not args['--print-betfair-only'],
keep_driver_alive = False)
if args['--bonus']:
worker.calc_bonus_profit(args['<websites>'])
elif args['--calc-best'] is not None:
o1, o2, o3 = args['--calc-best'].split(',')
worker.calc_best_shot(float(o1), float(o2), float(o3))
elif args['--calc-back'] is not None:
worker.calc_real_back_odd(args['--calc-back'])
elif args['--get-urls']:
worker.generate_compare_urls_file()
elif args['--get-lay-markets']:
worker.get_lay_markets()
elif args['--get-lay-markets-new']:
worker.get_lay_markets(new=True)
elif args['--compare']:
worker.compare_multiple_sites(int(args['--loop']))
elif args['--compare-one'] is not None:
worker.compare_back_and_lay(args['--compare-one'], int(args['--loop']))
elif args['--compare-race']:
worker.compare_with_race()
else:
worker.run(
websites_str=args['<websites>'],
leagues_str=args['<leagues>'],
is_get_only=args['--get-only'],
is_send_email_api=args['--send-email-api'],
is_send_email_smtp=args['--send-email-smtp'],
is_send_email_when_found=args['--send-email-when-found'],
loop_minutes=int(args['--loop']),
ask_gce=args['--ask-gce'],
gce_ip=args['--gce-ip'],
highlight=args['--highlight'],
betfair_limits=args['--betfair-limits'],
is_betfair=(args['--betfair']),
exclude=(args['--exclude']),
print_betfair_only=(args['--print-betfair-only'])
)
if __name__ == "__main__":
main()