Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Session Initialization #243

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ name: Build

on:
pull_request_target:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
make install_dev
- name: Run tests and coverage
run: make test_cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
make install_dev
- name: Run tests and coverage
run: make test_cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Change Log
==========

2.3.4
-----
## Update
- Use a different url to try and obtain cookies (fc.yahoo.com no longer works)
- Refactor how a session is initialized
- Use the country as a way to make the request to obtain cookies be more location specific

2.3.3
-----
## Update
- Try and obtain cookies and a crumb during `Ticker` initialization so they can be used in further requests.

2.3.2
-----
## Update
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guide/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ for i, row in df.iterrows():

# Or, pass all tickers to the Ticker instance
ticker_list = df['Tickers'].tolist()
ticker_list = list(set(_flatten_list(ticker_list)))
ticker_list = list(set(flatten_list(ticker_list)))
tickers = Ticker(ticker_list, session=r.session, crumb=r.crumb)
data = tickers.p_company_360
# Do something with data
Expand Down
1,194 changes: 653 additions & 541 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "yahooquery"
version = "2.3.3"
version = "2.3.4"
description = "Python wrapper for an unofficial Yahoo Finance API"
authors = ["Doug Guthrie <[email protected]>"]
documentation = "https://yahooquery.dpguthrie.com"
Expand All @@ -9,7 +9,7 @@ license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
python = ">=3.8.1,<4.0"
requests = "^2.31.0"
pandas = "^2.0.3"
requests-futures = "^1.0.1"
Expand All @@ -20,13 +20,13 @@ webdriver-manager = {version = "^3.8.6", optional = true}

[tool.poetry.dev-dependencies]
pytest = "^7.4.0"
isort = "^5.12.0"
isort = "^5.0.0"
flake8 = "^6.0.0"
mypy = "^1.4.1"
pytest-cov = "^4.1.0"
black = "^23.7.0"
pre-commit = "^3.3.3"
ipython = "^8.14.0"
ipython = "^8.0.0"
mkdocs-material = "^9.1.18"

[build-system]
Expand Down
129 changes: 84 additions & 45 deletions tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_adj_ohlc(ticker):
assert ticker.history(period="max", adj_ohlc=True) is not None


class TestHistoryDataframe():
class TestHistoryDataframe:
"""Tests for `utils.__init__._history_dataframe` and dependencies."""

@pytest.fixture
Expand Down Expand Up @@ -250,13 +250,20 @@ def timestamps_daily(self, utc, tz_oz, tz_us, tz_hk):

expected_utc = pd.DatetimeIndex(
[
'2022-11-04 13:30:00', '2022-11-07 14:30:00',
'2022-11-08 14:30:00', '2022-11-09 14:30:00',
'2022-11-10 14:30:00', '2022-11-11 14:30:00',
'2022-11-14 14:30:00', '2022-11-15 14:30:00',
'2022-11-16 14:30:00', '2022-11-17 14:30:00',
'2022-11-18 14:30:00', '2022-11-21 14:30:00',
'2022-11-22 14:30:00', '2022-11-23 14:30:00',
'2022-11-04 13:30:00',
'2022-11-07 14:30:00',
'2022-11-08 14:30:00',
'2022-11-09 14:30:00',
'2022-11-10 14:30:00',
'2022-11-11 14:30:00',
'2022-11-14 14:30:00',
'2022-11-15 14:30:00',
'2022-11-16 14:30:00',
'2022-11-17 14:30:00',
'2022-11-18 14:30:00',
'2022-11-21 14:30:00',
'2022-11-22 14:30:00',
'2022-11-23 14:30:00',
],
tz=utc,
)
Expand Down Expand Up @@ -284,13 +291,20 @@ def timestamps_daily(self, utc, tz_oz, tz_us, tz_hk):

expected_oz = pd.DatetimeIndex(
[
'2022-11-05 00:30:00', '2022-11-08 01:30:00',
'2022-11-09 01:30:00', '2022-11-10 01:30:00',
'2022-11-11 01:30:00', '2022-11-12 01:30:00',
'2022-11-15 01:30:00', '2022-11-16 01:30:00',
'2022-11-17 01:30:00', '2022-11-18 01:30:00',
'2022-11-19 01:30:00', '2022-11-22 01:30:00',
'2022-11-23 01:30:00', '2022-11-24 01:30:00',
'2022-11-05 00:30:00',
'2022-11-08 01:30:00',
'2022-11-09 01:30:00',
'2022-11-10 01:30:00',
'2022-11-11 01:30:00',
'2022-11-12 01:30:00',
'2022-11-15 01:30:00',
'2022-11-16 01:30:00',
'2022-11-17 01:30:00',
'2022-11-18 01:30:00',
'2022-11-19 01:30:00',
'2022-11-22 01:30:00',
'2022-11-23 01:30:00',
'2022-11-24 01:30:00',
],
tz=tz_oz,
)
Expand Down Expand Up @@ -318,13 +332,20 @@ def timestamps_daily(self, utc, tz_oz, tz_us, tz_hk):

expected_us = pd.DatetimeIndex(
[
'2022-11-04 09:30:00', '2022-11-07 09:30:00',
'2022-11-08 09:30:00', '2022-11-09 09:30:00',
'2022-11-10 09:30:00', '2022-11-11 09:30:00',
'2022-11-14 09:30:00', '2022-11-15 09:30:00',
'2022-11-16 09:30:00', '2022-11-17 09:30:00',
'2022-11-18 09:30:00', '2022-11-21 09:30:00',
'2022-11-22 09:30:00', '2022-11-23 09:30:00',
'2022-11-04 09:30:00',
'2022-11-07 09:30:00',
'2022-11-08 09:30:00',
'2022-11-09 09:30:00',
'2022-11-10 09:30:00',
'2022-11-11 09:30:00',
'2022-11-14 09:30:00',
'2022-11-15 09:30:00',
'2022-11-16 09:30:00',
'2022-11-17 09:30:00',
'2022-11-18 09:30:00',
'2022-11-21 09:30:00',
'2022-11-22 09:30:00',
'2022-11-23 09:30:00',
],
tz=tz_us,
)
Expand Down Expand Up @@ -352,13 +373,20 @@ def timestamps_daily(self, utc, tz_oz, tz_us, tz_hk):

expected_hk = pd.DatetimeIndex(
[
'2022-11-04 21:30', '2022-11-07 22:30',
'2022-11-08 22:30', '2022-11-09 22:30',
'2022-11-10 22:30', '2022-11-11 22:30',
'2022-11-14 22:30', '2022-11-15 22:30',
'2022-11-16 22:30', '2022-11-17 22:30',
'2022-11-18 22:30', '2022-11-21 22:30',
'2022-11-22 22:30', '2022-11-23 22:30',
'2022-11-04 21:30',
'2022-11-07 22:30',
'2022-11-08 22:30',
'2022-11-09 22:30',
'2022-11-10 22:30',
'2022-11-11 22:30',
'2022-11-14 22:30',
'2022-11-15 22:30',
'2022-11-16 22:30',
'2022-11-17 22:30',
'2022-11-18 22:30',
'2022-11-21 22:30',
'2022-11-22 22:30',
'2022-11-23 22:30',
],
tz=tz_hk,
)
Expand All @@ -370,7 +398,11 @@ def timestamps_daily(self, utc, tz_oz, tz_us, tz_hk):
)

yield (
tss, expected_us_days, expected_oz_days, expected_hk_days, expected_utc_days
tss,
expected_us_days,
expected_oz_days,
expected_hk_days,
expected_utc_days,
)

@pytest.fixture
Expand Down Expand Up @@ -451,12 +483,7 @@ def get_splits(tss):
indice = 11
ts = tss[indice]
d = {
str(ts): {
'data': ts,
'numerator': 3,
'denominator': 1,
'splitRatio': '3:1'
}
str(ts): {'data': ts, 'numerator': 3, 'denominator': 1, 'splitRatio': '3:1'}
}
expected = [3 if i == indice else float('nan') for i in range(14)]
return d, expected
Expand Down Expand Up @@ -606,7 +633,10 @@ def f(data, adj_timezone):
dividends, _ = dividends_daily

expecteds = (
expected_daily_utc, expected_daily_us, expected_daily_oz, expected_daily_hk
expected_daily_utc,
expected_daily_us,
expected_daily_oz,
expected_daily_hk,
)
tzs = (utc, tz_us, tz_oz, tz_hk)
for expected, tz in zip(expecteds, tzs):
Expand Down Expand Up @@ -663,7 +693,9 @@ def test_live_indice(
# verify live indice has local timezone when adj_timezone True
rtrn = _history_dataframe(data, daily=True, adj_timezone=True)
expected_li = pd.Timestamp("2022-11-23 14:31", tz=tz_us).to_pydatetime()
expected_index = expected_index[:-1].insert(len(expected_index)-1, expected_li)
expected_index = expected_index[:-1].insert(
len(expected_index) - 1, expected_li
)
expected_df.index = expected_index
assert_frame_equal(rtrn, expected_df)

Expand Down Expand Up @@ -728,13 +760,20 @@ def timestamps_intraday(self, utc):

expected_index_utc = pd.DatetimeIndex(
[
'2022-11-04 13:30:00', '2022-11-04 14:30:00',
'2022-11-04 15:30:00', '2022-11-04 16:30:00',
'2022-11-04 17:30:00', '2022-11-04 18:30:00',
'2022-11-04 19:30:00', '2022-11-07 14:30:00',
'2022-11-07 15:30:00', '2022-11-07 16:30:00',
'2022-11-07 17:30:00', '2022-11-07 18:30:00',
'2022-11-07 19:30:00', '2022-11-07 20:30:00'
'2022-11-04 13:30:00',
'2022-11-04 14:30:00',
'2022-11-04 15:30:00',
'2022-11-04 16:30:00',
'2022-11-04 17:30:00',
'2022-11-04 18:30:00',
'2022-11-04 19:30:00',
'2022-11-07 14:30:00',
'2022-11-07 15:30:00',
'2022-11-07 16:30:00',
'2022-11-07 17:30:00',
'2022-11-07 18:30:00',
'2022-11-07 19:30:00',
'2022-11-07 20:30:00',
],
tz=utc,
)
Expand Down
2 changes: 1 addition & 1 deletion yahooquery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Python interface to unofficial Yahoo Finance API endpoints"""

name = "yahooquery"
__version__ = "2.3.2"
__version__ = "2.3.4"

from .research import Research # noqa
from .ticker import Ticker # noqa
Expand Down
Loading
Loading