Skip to content

Commit

Permalink
Merge pull request #158 from JECSand/development
Browse files Browse the repository at this point in the history
Fix for #157
  • Loading branch information
JECSand authored Oct 30, 2023
2 parents 38bfa21 + 9401c4e commit 0aea321
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@
1.15 06/21/2023 -- Minimized sleeps in between 400 errors to less than 10 seconds.
1.16 07/17/2023 -- Minor code cleanup in test_yahoofinancials.py.
1.16 07/17/2023 -- Fixed HTTP 401 error when executing get_current_price() as reported in #152.
1.17 10/30/2023 -- Added a fix for 404 error reported in #157.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ A python module that returns stock, cryptocurrency, forex, mutual fund, commodit
.. image:: https://static.pepy.tech/badge/yahoofinancials/week
:target: https://pepy.tech/project/yahoofinancials

Current Version: v1.16
Current Version: v1.17

Version Released: 07/17/2023
Version Released: 10/30/2023

Report any bugs by opening an issue here: https://github.com/JECSand/yahoofinancials/issues

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

setup(
name='yahoofinancials',
version='1.16',
version='1.17',
description='A powerful financial data module used for pulling both fundamental and technical data from Yahoo Finance',
long_description=long_description,
url='https://github.com/JECSand/yahoofinancials',
download_url='https://github.com/JECSand/yahoofinancials/archive/1.16.tar.gz',
download_url='https://github.com/JECSand/yahoofinancials/archive/1.17.tar.gz',
author='Connor Sanders',
author_email='[email protected]',
license='MIT',
Expand Down
4 changes: 2 additions & 2 deletions test/test_yahoofinancials.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# YahooFinancials Unit Tests v1.16
# Version Released: 07/17/2023
# YahooFinancials Unit Tests v1.17
# Version Released: 10/30/2023
# Author: Connor Sanders
# Tested on Python 3.7, 3.8, 3.9, 3.10, and 3.11
# Copyright (c) 2023 Connor Sanders <[email protected]>
Expand Down
6 changes: 5 additions & 1 deletion yahoofinancials/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import requests as requests

from yahoofinancials.maps import COUNTRY_MAP, REQUEST_MAP, USER_AGENTS
from yahoofinancials.sessions import _init_session
from yahoofinancials.utils import remove_prefix, get_request_config, get_request_category

# track the last get timestamp to add a minimum delay between gets - be nice!
Expand Down Expand Up @@ -66,6 +67,7 @@ def __init__(self, ticker, **kwargs):
self.timeout = kwargs.get("timeout", 30)
self.proxies = kwargs.get("proxies")
self._cache = {}
self.session, self.crumb = _init_session(kwargs.pop("session", None), **kwargs)

# Minimum interval between Yahoo Finance requests for this instance
_MIN_INTERVAL = 7
Expand Down Expand Up @@ -180,10 +182,12 @@ def _construct_url(self, symbol, config, params, freq, request_type):

# Private method to execute a web scrape request and decrypt the return
def _request_handler(self, url, res_field=""):
urlopener = UrlOpener()
urlopener = UrlOpener(self.session)
# Try to open the URL up to 10 times sleeping random time if something goes wrong
cur_url = url
max_retry = 10
if 'quoteSummary' in cur_url:
cur_url += "&crumb=" + self.crumb
for i in range(0, max_retry):
response = urlopener.open(cur_url, proxy=self._get_proxy(), timeout=self.timeout)
if response.status_code != 200:
Expand Down
2 changes: 1 addition & 1 deletion yahoofinancials/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@

REQUEST_MAP = {
"quoteSummary": {
"path": "https://query2.finance.yahoo.com/v6/finance/quoteSummary/{symbol}",
"path": "https://query2.finance.yahoo.com/v10/finance/quoteSummary/{symbol}",
"response_field": "quoteSummary",
"request": {
"formatted": {"required": False, "default": False},
Expand Down
173 changes: 173 additions & 0 deletions yahoofinancials/sessions.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions yahoofinancials/yf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
==============================
The Yahoo Financials Module
Version: 1.16
Version: 1.17
==============================
Author: Connor Sanders
Email: [email protected]
Version Released: 07/17/2023
Email: [email protected]
Version Released: 10/30/2023
Tested on Python 3.7, 3.8, 3.9, 3.10, and 3.11
Copyright (c) 2023 Connor Sanders
Expand Down Expand Up @@ -44,7 +44,7 @@
from yahoofinancials.calcs import num_shares_outstanding, eps
from yahoofinancials.etl import YahooFinanceETL

__version__ = "1.16"
__version__ = "1.17"
__author__ = "Connor Sanders"


Expand Down

0 comments on commit 0aea321

Please sign in to comment.