From 28d2bda75ac6618b3517d453a7980adf37188b5e Mon Sep 17 00:00:00 2001 From: alt Date: Wed, 29 Aug 2018 02:09:05 -0500 Subject: [PATCH] v1.2 testing6 --- test/test_yahoofinancials.py | 4 ++-- yahoofinancials/__init__.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/test_yahoofinancials.py b/test/test_yahoofinancials.py index b2adaf3..b52a878 100644 --- a/test/test_yahoofinancials.py +++ b/test/test_yahoofinancials.py @@ -82,9 +82,9 @@ def test_yf_fundamentals(self): # Historical Price Test def test_yf_historical_price(self): single_stock_prices = self.test_yf_stock_single.get_historical_price_data('2015-01-15', '2017-10-15', 'weekly') - expect_dict = {'high': 48.2400016784668, 'volume': 81106400, 'formatted_date': '2015-01-12', + expect_dict = {'high': 49.099998474121094, 'volume': 125737200, 'formatted_date': '2015-01-12', 'low': 46.599998474121094, 'adjclose': 45.669029235839844, 'date': 1421038800, - 'close': 47.61000061035156, 'open': 48.060001373291016} + 'close': 47.61000061035156, 'open': 48.959999084472656} self.assertDictEqual(single_stock_prices['C']['prices'][0], expect_dict) # Extra Module Methods Test diff --git a/yahoofinancials/__init__.py b/yahoofinancials/__init__.py index 28bcb5a..42a2049 100644 --- a/yahoofinancials/__init__.py +++ b/yahoofinancials/__init__.py @@ -43,6 +43,7 @@ """ import sys +import calendar import re from json import loads import time @@ -109,10 +110,11 @@ def format_date(in_date): if isinstance(in_date, str): year, month, day = in_date.split()[0].split('-') d = date(int(year), int(month), int(day)) - form_date = int(time.mktime(d.timetuple())) + #form_date = int(time.mktime(d.timetuple())) + form_date = int(calendar.timegm(time.strptime(in_date, '%Y-%m-%d'))) else: form_date = str((datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=in_date)).date()) - print(in_date) + print(form_date) return form_date # Private Static Method to Convert Eastern Time to UTC @@ -292,7 +294,7 @@ def _build_api_url(hist_obj, up_ticker): str(hist_obj['end']) + '&interval=' + hist_obj['interval'] api_url += '&events=div|split|earn&lang=en-US®ion=US' print(api_url) - return "https://query1.finance.yahoo.com/v8/finance/chart/C?symbol= C&period1=1421301600&period2=1508043600&interval=1wk&events=div|split|earn&lang=en-US®ion=US" + return api_url # Private Static Method to get financial data via API Call @staticmethod