Skip to content

Commit 61c417a

Browse files
committed
patch download to process files
1 parent 5c1c06d commit 61c417a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

cot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def process(lines_of_cot, commodity_name='EURO FX'):
4343
'short': changes[4],
4444
'spreads': changes[5]}}
4545

46-
return results
46+
return results, current, changes
4747

4848
return 0
4949

@@ -131,7 +131,7 @@ def _visualize(json_data, currency, report_date):
131131
report_date = None
132132

133133
with open(report, 'r') as fd:
134-
data = process(fd.readlines(), arguments['<currency>'])
134+
data, current, changes = process(fd.readlines(), arguments['<currency>'])
135135
_visualize(data, arguments['<currency>'], report_date)
136136

137137

download_all_cot.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
"""
2-
Downloading all COT reports from the offical source
2+
Downloading all COT reports from the official source
3+
and adding some info as a CSV
34
45
Jon V (darksun4@gmail.com)
56
23rd of January 2017
67
"""
78
from datetime import datetime, timedelta
8-
from cot import _download_report
9+
from cot import _download_report, process
910

1011
if __name__ == "__main__":
12+
csv_file = open("all_data.csv", "w+")
13+
csv_file.write("non_com_long;non_com_short;spreads;com_long;com_short\n")
14+
1115
start, end = datetime(2005, 01, 4), datetime(2017, 01, 23)
1216
days = (start + timedelta(days=i) for i in range((end - start).days + 1))
1317
all_tuesdays = [d for d in days if d.weekday() == 1]
@@ -16,8 +20,16 @@
1620

1721
for tuesday in all_tuesdays:
1822
str_tuesday = str(tuesday.month).zfill(2) + "/" + str(tuesday.day).zfill(2) + "/" + str(tuesday.year)
19-
23+
2024
try:
21-
print _download_report(str_tuesday)
25+
report =_download_report(str_tuesday)
26+
with open(report, 'r') as fd:
27+
data, current, changes = process(fd.readlines(), 'EURO')
28+
for c in current[:5]:
29+
csv_file.write(c+";")
30+
csv_file.write(str_tuesday+"\n")
2231
except:
2332
print "Something went wrong"
33+
34+
35+

0 commit comments

Comments
 (0)