Skip to content

Commit

Permalink
screen(): tweak argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Jan 13, 2025
1 parent ca3664f commit 004c0bd
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions yfinance/screener/screener.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ def screen(query: Union[str, QueryBase],
if size is not None and size > 250:
raise ValueError("Yahoo limits query size to 250, reduce size.")

fields = locals()
for k in ['query', 'session', 'proxy']:
if k in fields:
del fields[k]

params_dict = {"corsDomain": "finance.yahoo.com", "formatted": "false", "lang": "en-US", "region": "US"}

args = locals()
post_query = None
if isinstance(query, str):
if query not in PREDEFINED_SCREENER_QUERIES.keys():
Expand All @@ -129,29 +133,24 @@ def screen(query: Union[str, QueryBase],
# Switch to Yahoo's predefined endpoint
_data = YfData(session=session)
params_dict['scrIds'] = query
# for k,v in args:
for k in defaults.keys():
v = args[k]
for k,v in fields.items():
if v is not None:
params_dict[k] = v
resp = _data.get(url=_PREDEFINED_URL_, params=params_dict, proxy=proxy)
resp.raise_for_status()
return resp.json()["finance"]["result"][0]

elif isinstance(query, QueryBase):
for k in ['session', 'proxy']:
if k in args:
del args[k]

# Prepare other fields
for k in defaults:
if k not in args:
args[k] = defaults[k]
args['sortType'] = 'ASC' if args['sortAsc'] else 'DESC'
del args['sortAsc']
if k not in fields:
fields[k] = defaults[k]
fields['sortType'] = 'ASC' if fields['sortAsc'] else 'DESC'
del fields['sortAsc']

del args['query']
post_query = args
del fields['query']
post_query = fields
post_query['query'] = query

else:
Expand Down

0 comments on commit 004c0bd

Please sign in to comment.