-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
31 lines (29 loc) · 845 Bytes
/
parse.py
File metadata and controls
31 lines (29 loc) · 845 Bytes
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
import datetime
import calendar
def parse_contract_name(name):
if name.startswith('Price of Bitcoin end'):
pass
elif name.startswith('Price of Bitcoin'):
return parse_bitcoin_option_contract(name)
elif name.startswith('Next Bitcoin network difficulty'):
pass
elif name.startswith('Bitcoin network difficult'):
pass
elif name.startswith('Bitcoin price to reach'):
pass
else:
print('Unknown bitcoin contract name: %s' % name)
def parse_bitcoin_option_contract(name):
tokens = name.split(' ')
month = 0
for i, month_name in enumerate(calendar.month_name):
if tokens[3] == month_name:
month = i
try:
day = int(tokens[4][:2])
except ValueError:
day = int(tokens[4][0])
date = datetime.datetime(2014, month, day)
strike_price = float(tokens[9][1:])
data = {'date': date, 'strike_price': strike_price}
return data