-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomei_quantity.py
58 lines (49 loc) · 1.23 KB
/
omei_quantity.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
import requests
import numpy
f = open('OMEI_stot_links.txt', 'r')
links = f.readlines()
f.close()
quant = {}
month_prev = 0
year_prev = 0
for link in links:
file_number = link.split("phf_stot_")[1]
year = file_number[0:4]
if True:
#int(year)>2014
r= requests.get(link.strip())
if r.status_code==200:
# print(r.text)
month = file_number[4:6]
if int(year) != int(year_prev) and int(year_prev)>0:
print(year_prev)
numpy.save('quant_'+year_prev+'.npy', quant)
quant = {}
year_prev = year
lines = r.text.split("\n")
iterlines = iter(lines)
next(iterlines)
for line in iterlines:
print(line)
break
break
#year,month,day,hour,low/high
text = line.split(";")
if len(text)>=7:
# year, month, day, hour, session, hig/low
key = (int(text[0]),int(text[1]),int(text[2]),int(text[3]),int(session))
prices[key+("high",)] = float(text[4])
prices[key+("low",)] = float(text[5])
#print prices
#print row
#if len(prices)==0:
# prices = row
#else:
# prices=numpy.vstack([prices,row])
#print(prices)
else:
print(link)
print(r.status_code)
#numpy.save('prices.npy', prices)
print(year_prev)
numpy.save('quant'+year_prev+'.npy', quant)