-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvd.py
executable file
·46 lines (37 loc) · 1.08 KB
/
csvd.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
#!/usr/bin/env python
# Author: Chico
# Version: 0.1.0
#
#
#
import sys;
import csv;
import urllib2;
def downloadCSV (stock):
#url = 'http://www.google.com/finance/historical?q=' + stock + '&histperiod=daily&startdate=Aug+8+2015&enddate=Aug+8+2016&output=csv'
url = 'http://www.google.com/finance/historical?q=' + urllib2.quote('vale5') + '&histperiod=' + urllib2.quote('daily') + \
'&startdate=' + urllib2.quote('Sep+21+2015') + '&enddate=' + urllib2.quote('Sep+21+2016') + '&output=csv'
print(url)
try:
response = urllib2.urlopen(url).read()
except Exception as e:
print(e)
raise e
return response
def openCsv (stock_name):
csvReader = csv.reader(stock_name)
return csvReader
def closeList (csv):
tempList = []
for row in csv:
if csv.line_num == 1:
continue
tempList.append(row[4])
tempList.reverse()
return tempList
def main():
csvFile = downloadCSV('vale5')
csvOpenFile = openCsv(csvFile)
print(closeList(csvOpenFile))
if __name__ == '__main__':
sys.exit(main())