Update main.py

This commit is contained in:
Andrew Dinh 2018-12-16 14:46:56 -08:00
parent 7986f2c6c1
commit eba040ede9

91
main.py
View File

@ -2,76 +2,33 @@
# Andrew Dinh # Andrew Dinh
# Python 3.6.1 # Python 3.6.1
# Description: Get, parse, and interpret JSON files from IEX # Description: Get, parse, and interpret JSON files from IEX
import urllib.request import urllib, requests, json
import re
#import os, errno
import json
file_path = "tmp/data.txt" class iex:
# directory = os.path.dirname(file_path)
url = urllib.request.urlopen("https://api.iextrading.com/1.0/stock/aapl/chart") def __init__(self, newStock = 'spy')
#print("url =", url) self.iex
html = url.read() # this is not a string, must convert it for findall()
# print("the html =", html)
myFile = open('data.json','r') def printDates(self)
data = myFile.read() print("Getting data from IEX...")
url = ''.join(('https://api.iextrading.com/1.0/stock/', stock, '/chart/5y'))
#link = "https://api.iextrading.com/1.0/stock/spy/chart/5y"
print("URL:", url)
f = requests.get(url)
#print(f.text)
json_data = f.text
loaded_json = json.loads(json_data)
#print(json_data)
#print(loaded_json)
#print(loaded_json[0])
json_string = json.dumps(data) print("Printing dates given from IEX...")
print("json string:", data) for i in range (0,len(loaded_json),1):
a = loaded_json[i]
print(a['date'])
''' def main():
myFile =open(file_path,'w') stock = 'spy'
myFile.write(str(html)) IEX(stock)
myFile.close()
main()
# Create tmp folder
try:
os.makedirs(directory)
except OSError as e:
if e.errno != errno.EEXIST:
raise
myFile = open(file_path,'r')
listOfLines = myFile.read().split('}')
#print("fileAsList:\n",listOfLines)
print(listOfLines[0],"\n")
print(listOfLines[1])
'''
'''
for j in range(0,len(listOfLines),1):
aLine = listOfLines[j]
#print(aLine)
lineData = aLine.split()
#print(lineData)
'''
'''
url = urllib.request.urlopen("http://www.gavilan.edu/staff/dir.php")
print("url =", url)
html = url.read() # this is not a string, must convert it for findall()
# print("-----------------------------------------------")
# print("the html =", html)
myFile = open('dataFile.txt','w')
myFile.write(str(html))
myFile.close()
myFile = open('dataFile.txt','r')
listOfLines = myFile.readlines() # returns a list of lines,USE for search()
#print("fileAsList:\n",listOfLines)
listOfEmails = re.findall(r'\w+@gavilan.edu', str(html))
# print(listOfEmails)
myFile.close()
myFile = open('dataFile.txt','r')
listOfLines = myFile.readlines()
for line in listOfLines:
match = re.search('stoykov',str(line))
if match:
print(line)
myFile.close()
'''