From 6904418629be05220df24e84fc3c14bbb25e6296 Mon Sep 17 00:00:00 2001 From: edgineer Date: Tue, 17 Dec 2019 18:59:04 -0800 Subject: [PATCH 1/4] Create .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f85c6b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.py \ No newline at end of file From f5000ba6ee12f8d8c9320f90ab7f66c6064196c0 Mon Sep 17 00:00:00 2001 From: edgineer Date: Tue, 17 Dec 2019 20:01:32 -0800 Subject: [PATCH 2/4] Update URL to retrieve stock earnings history --- options.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/options.py b/options.py index 393b050..dde1fd9 100644 --- a/options.py +++ b/options.py @@ -6,7 +6,9 @@ import datetime def getEarningsHistoryHTML(stock): - fp = urllib.request.urlopen("https://www.nasdaq.com/earnings/report/{}".format(stock)) + s = "https://www.nasdaq.com/market-activity/stocks/{}/earnings".format(stock) + print(s) + fp = urllib.request.urlopen(s) byteArr = fp.read() html = byteArr.decode("utf8") fp.close() From 6bfc423776b22d23397e65ab1eb86024b3610b28 Mon Sep 17 00:00:00 2001 From: edgineer Date: Tue, 17 Dec 2019 20:03:05 -0800 Subject: [PATCH 3/4] Update gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f85c6b1..dd19c04 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -config.py \ No newline at end of file +config.py +__pycache__ \ No newline at end of file From 166257f85bb0ea433964d56d1957c44b8801dabd Mon Sep 17 00:00:00 2001 From: edgineer Date: Thu, 19 Dec 2019 18:06:16 -0800 Subject: [PATCH 4/4] change to requests library --- options.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/options.py b/options.py index dde1fd9..7c4287a 100644 --- a/options.py +++ b/options.py @@ -1,17 +1,16 @@ from bs4 import BeautifulSoup -import urllib.request from config import API_KEY from alpha_vantage.timeseries import TimeSeries import json import datetime +import requests def getEarningsHistoryHTML(stock): + headers = {'User-Agent': 'Mozilla/5.0'} s = "https://www.nasdaq.com/market-activity/stocks/{}/earnings".format(stock) - print(s) - fp = urllib.request.urlopen(s) - byteArr = fp.read() + fp = requests.get(s, headers=headers) + byteArr = fp.content html = byteArr.decode("utf8") - fp.close() return html def getDate(quarterReport): @@ -21,6 +20,7 @@ def getPastEarningsDates(stock): pastEarningsDates = [] soup = BeautifulSoup(getEarningsHistoryHTML(stock), 'html.parser') table = soup.table.find_all('tr') + print(table) for i in range(1, len(table)): quarterReport = table[i] date = getDate(quarterReport)