From 43736652ff370d58c20337c1d21ec65b0c2e8020 Mon Sep 17 00:00:00 2001 From: Andrew Dinh Date: Sat, 15 Dec 2018 17:56:29 -0800 Subject: [PATCH 1/2] Update main.py --- main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/main.py b/main.py index e69de29..5e3770e 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,48 @@ +# main.py +# Andrew Dinh +# Python 3.6.1 +# Description: Get, parse, and interpret JSON files from IEX +import urllib.request +import re +import os + +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("-----------------------------------------------") +# print("the html =", html) + +if not os.path.exists(temporary): + os.makedirs(temporary) + +myFile = open('temporary/data.txt','r') +listOfLines = myFile.readlines() +print("fileAsList:\n",listOfLines) + + +''' +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() +''' \ No newline at end of file From 7986f2c6c1657aeaf78905460b33fada25fa1b1a Mon Sep 17 00:00:00 2001 From: Andrew Dinh <45807756+andrewkdinh@users.noreply.github.com> Date: Sun, 16 Dec 2018 20:11:25 +0000 Subject: [PATCH 2/2] Update main.py --- main.py | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 5e3770e..a194fe4 100644 --- a/main.py +++ b/main.py @@ -4,21 +4,50 @@ # Description: Get, parse, and interpret JSON files from IEX import urllib.request import re -import os +#import os, errno +import json + +file_path = "tmp/data.txt" +# directory = os.path.dirname(file_path) url = urllib.request.urlopen("https://api.iextrading.com/1.0/stock/aapl/chart") -print("url =", url) +#print("url =", url) html = url.read() # this is not a string, must convert it for findall() -# print("-----------------------------------------------") # print("the html =", html) -if not os.path.exists(temporary): - os.makedirs(temporary) +myFile = open('data.json','r') +data = myFile.read() -myFile = open('temporary/data.txt','r') -listOfLines = myFile.readlines() -print("fileAsList:\n",listOfLines) +json_string = json.dumps(data) +print("json string:", data) +''' +myFile =open(file_path,'w') +myFile.write(str(html)) +myFile.close() + + +# 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") @@ -45,4 +74,4 @@ for line in listOfLines: if match: print(line) myFile.close() -''' \ No newline at end of file +'''