yahooquery icon indicating copy to clipboard operation
yahooquery copied to clipboard

`calendar_events` - fetch historic, not just upcoming

Open ValueRaider opened this issue 2 years ago • 3 comments

dat.calendar_events currently returns the next earnings event, which I assume is same as shown on the quote page https://finance.yahoo.com/quote/AAPL?p=AAPL&.tsrc=fin-srch

But on the Earnings Calendar page https://finance.yahoo.com/calendar/earnings?symbol=AAPL it shows past dates too - these are useful, can they be fetched?

image

ValueRaider avatar Feb 27 '23 21:02 ValueRaider

You have to have a crumb to do this, which from what I remember since the last time I tried, is not easy to do.

image image

dpguthrie avatar Feb 28 '23 00:02 dpguthrie

Lots of really cool stuff here though if we can figure out how to get the crumb and add it to the Session.

https://github.com/dpguthrie/yahooquery/blob/444855ec92a55883d7e08586aaa851c1ee346081/yahooquery/base.py#L824

dpguthrie avatar Feb 28 '23 00:02 dpguthrie

With a little help from GPT here is code to get the crumb:

import requests, re, json
def get_crumb():
    response = requests.get("https://finance.yahoo.com")
    pat = re.compile(r'window\.YAHOO\.context = ({.*?});', re.DOTALL)
    match = re.search(pat, response.text)
    if match:
        js_dict = json.loads(match.group(1))
        return js_dict.get('crumb')
    return None

print(get_crumb())

I'm hoping you can integrate this in because I find the codebase hard to navigate. Maybe a "Developers Guide" could be useful.

ValueRaider avatar May 23 '23 13:05 ValueRaider