|
31 | 31 |
|
32 | 32 |
|
33 | 33 | from . import utils, cache |
34 | | -from .const import _MIC_TO_YAHOO_SUFFIX, _NEWS_GRAPHQL_QUERY_, _NEWS_GRAPHQL_URL_, _SENTINEL_ |
| 34 | +from .const import _MIC_TO_YAHOO_SUFFIX, _SENTINEL_ |
35 | 35 | from .data import YfData |
36 | 36 | from .config import YfConfig |
37 | 37 | from .exceptions import YFDataException, YFEarningsDateMissing, YFRateLimitError |
|
49 | 49 | from bs4 import BeautifulSoup |
50 | 50 |
|
51 | 51 |
|
| 52 | +_NEWS_GRAPHQL_URL_ = 'https://nexus-finance-prod.media.yahoo.com/' |
| 53 | + |
| 54 | +# GraphQL query behind the news list on finance.yahoo.com/quote/<symbol>/news/. |
| 55 | +# Assets only resolve when a field takes $clientContext (previewUrl, clickthroughUrl), |
| 56 | +# otherwise Yahoo returns an "AssetError" for every item. |
| 57 | +_NEWS_GRAPHQL_QUERY_ = ''' |
| 58 | +query FinanceTickerListNews($listInput: LightyearListInput!, $clientContext: ClientContext!, $mlRecsInput: MLRecsInput!, $gqlContext: [GqlContext] = [], $imageResize: [ImageResizeInput!]! = [], $mlRecsFirst: Int, $after: String) { |
| 59 | + lightyearList: financeTickerList(list_input: $listInput, cc: $clientContext) { |
| 60 | + main: mlRecsStream(mlRecsInput: $mlRecsInput, first: $mlRecsFirst, after: $after) { |
| 61 | + edges { node { asset(gqlContext: $gqlContext) { |
| 62 | + __typename |
| 63 | + ... on Story { id: uuid title previewUrl(cc: $clientContext) isPremiumNews contentAttributes { ...Attrs } finance { ...Tickers } } |
| 64 | + ... on Video { id: uuid title previewUrl(cc: $clientContext) contentAttributes { ...Attrs } finance { ...Tickers } } |
| 65 | + ... on Outlink { id: uuid title: headline description displayTime url provider { displayName url } contentAttributes { thumbnail { ...Image } } } |
| 66 | + } } } |
| 67 | + pageInfo { hasNextPage endCursor } |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | +fragment Image on Image { url height width resized(resizeInput: $imageResize) { url height width transformLabel } } |
| 72 | +fragment Attrs on ContentAttributes { |
| 73 | + description summary publishTime displayTime isHosted canonicalUrl clickthroughUrl(cc: $clientContext) |
| 74 | + provider { displayName url } thumbnail { ...Image } |
| 75 | +} |
| 76 | +fragment Tickers on Finance { stockTickers { symbol } } |
| 77 | +''' |
| 78 | + |
52 | 79 | _tz_info_fetch_ctr = 0 |
53 | 80 |
|
54 | 81 | class TickerBase: |
@@ -619,9 +646,12 @@ def get_news(self, count=10, tab="news") -> list: |
619 | 646 | News follows ``yf.config.locale``. Yahoo only has news for some locales; |
620 | 647 | for others an empty list is returned. |
621 | 648 |
|
622 | | - :param count: maximum number of articles to return |
623 | | - :param tab: "news", "all" or "press releases" |
624 | | - :return: list of articles, each ``{"id": ..., "content": {...}}`` |
| 649 | + Args: |
| 650 | + count (int): Maximum number of articles to return |
| 651 | + tab (str): "news", "all" or "press releases" |
| 652 | +
|
| 653 | + Returns: |
| 654 | + list of articles, each ``{"id": ..., "content": {...}}`` |
625 | 655 | """ |
626 | 656 | logger = utils.get_yf_logger() |
627 | 657 |
|
|
0 commit comments