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
# Python 3.6.1
# Description: Get, parse, and interpret JSON files from IEX
import urllib.request
import re
#import os, errno
import json
import urllib, requests, json
file_path = "tmp/data.txt"
# directory = os.path.dirname(file_path)
class iex:
url = urllib.request.urlopen("https://api.iextrading.com/1.0/stock/aapl/chart")
#print("url =", url)
html = url.read() # this is not a string, must convert it for findall()
# print("the html =", html)
def __init__(self, newStock = 'spy')
self.iex
myFile = open('data.json','r')
data = myFile.read()
def printDates(self)
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("json string:", data)
print("Printing dates given from IEX...")
for i in range (0,len(loaded_json),1):
a = loaded_json[i]
print(a['date'])
'''
myFile =open(file_path,'w')
myFile.write(str(html))
myFile.close()
def main():
stock = 'spy'
IEX(stock)
# 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()
'''
main()