From 90d1afacb0c652ee40de710abd4694ab439ef965 Mon Sep 17 00:00:00 2001 From: slikdijit <68885229+slikdijit@users.noreply.github.com> Date: Sat, 17 Apr 2021 00:22:46 -0400 Subject: [PATCH 1/2] added networking error --- yahoo_earnings_calendar/scraper.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/yahoo_earnings_calendar/scraper.py b/yahoo_earnings_calendar/scraper.py index 09412ba..c63fcba 100644 --- a/yahoo_earnings_calendar/scraper.py +++ b/yahoo_earnings_calendar/scraper.py @@ -34,6 +34,11 @@ def __init__(self, delay=SLEEP_BETWEEN_REQUESTS_S): def _get_data_dict(self, url): time.sleep(self.delay) page = requests.get(url) + + print(page.status_code) + if page.status_code == 503: + raise Exception(f"{page.status_code} BAD CONNECTION") + page_content = page.content.decode(encoding='utf-8', errors='strict') page_data_string = [row for row in page_content.split( '\n') if row.startswith('root.App.main = ')][0][:-1] @@ -53,8 +58,9 @@ def get_next_earnings_date(self, symbol): try: page_data_dict = self._get_data_dict(url) return page_data_dict['context']['dispatcher']['stores']['QuoteSummaryStore']['calendarEvents']['earnings']['earningsDate'][0]['raw'] - except: - raise Exception('Invalid Symbol or Unavailable Earnings Date') + except Exception as e: + print(e) + # raise Exception('Invalid Symbol or Unavailable Earnings Date') def earnings_on(self, date, offset=0, count=1): """Gets earnings calendar data from Yahoo! on a specific date. @@ -153,8 +159,9 @@ def get_earnings_of(self, symbol): try: page_data_dict = self._get_data_dict(url) return page_data_dict["context"]["dispatcher"]["stores"]["ScreenerResultsStore"]["results"]["rows"] - except: - raise Exception('Invalid Symbol or Unavailable Earnings Date') + except Exception as e: + print(e) + # raise Exception('Invalid Symbol or Unavailable Earnings Date') if __name__ == '__main__': # pragma: no cover date_from = datetime.datetime.strptime( From f57347dfd19ccd0a94ac2c3fc28ed4332273314f Mon Sep 17 00:00:00 2001 From: slikdijit <68885229+slikdijit@users.noreply.github.com> Date: Sat, 17 Apr 2021 00:32:01 -0400 Subject: [PATCH 2/2] updated, semi final --- yahoo_earnings_calendar/scraper.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/yahoo_earnings_calendar/scraper.py b/yahoo_earnings_calendar/scraper.py index c63fcba..e755519 100644 --- a/yahoo_earnings_calendar/scraper.py +++ b/yahoo_earnings_calendar/scraper.py @@ -35,8 +35,7 @@ def _get_data_dict(self, url): time.sleep(self.delay) page = requests.get(url) - print(page.status_code) - if page.status_code == 503: + if page.status_code != 200: raise Exception(f"{page.status_code} BAD CONNECTION") page_content = page.content.decode(encoding='utf-8', errors='strict') @@ -60,7 +59,6 @@ def get_next_earnings_date(self, symbol): return page_data_dict['context']['dispatcher']['stores']['QuoteSummaryStore']['calendarEvents']['earnings']['earningsDate'][0]['raw'] except Exception as e: print(e) - # raise Exception('Invalid Symbol or Unavailable Earnings Date') def earnings_on(self, date, offset=0, count=1): """Gets earnings calendar data from Yahoo! on a specific date. @@ -161,7 +159,6 @@ def get_earnings_of(self, symbol): return page_data_dict["context"]["dispatcher"]["stores"]["ScreenerResultsStore"]["results"]["rows"] except Exception as e: print(e) - # raise Exception('Invalid Symbol or Unavailable Earnings Date') if __name__ == '__main__': # pragma: no cover date_from = datetime.datetime.strptime(