-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcsvdata.py
More file actions
25 lines (20 loc) · 756 Bytes
/
csvdata.py
File metadata and controls
25 lines (20 loc) · 756 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
#!/usr/bin/python
#csvdata.py
# Chapter 17 Stock Market
# Author: William C. Gunnells
# Rapid Python Programming
# libs
import urllib
import time
import datetime
stockpull='AAPL' # this can be a list to loop through
def MyStock(stock):
print "Get stock data", stock
print str(datetime.datetime.fromtimestamp(time.time()).strftime('%y-%m-%d %H:%M:%S'))
url="http://chartapi.finance.yahoo.com/instrument/1.0/"+stock+"/chartdata;type=quote;range=1y/csv"
#url="http://chartapi.finance.yahoo.com/instrument/1.0/"+stock+"/chartdata;type=quote;range=10d/csv"
#url="http://chartapi.finance.yahoo.com/instrument/1.0/"+stock+"/chartdata;type=quote;range=1d/csv"
response=urllib.urlopen(url)
html=response.read()
print html
MyStock(stockpull)