OpenBagTwo/MarketWatch

Not all articles have a pillarName

Offen

#4 geöffnet am 12.09.2024

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Jupyter Notebook (1 Fork)auto 404
buggood first issuehelp wantedquestion

Repository-Metriken

Stars
 (3 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Had two runs over the past few weeks fail with the traceback:

Traceback (most recent call last):
  File "/home/runner/work/MarketWatch/MarketWatch/post_generator.py", line 297, in <module>
    generate_post(os.environ["GUARDIAN_API_KEY"], date)
  File "/home/runner/work/MarketWatch/MarketWatch/post_generator.py", line 265, in generate_post
    article = get_random_article(guardian_api_key, date)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/MarketWatch/MarketWatch/post_generator.py", line 196, in get_random_article
    "tags": [article["pillarName"]],
             ~~~~~~~^^^^^^^^^^^^^^
KeyError: 'pillarName'

The obvious solution would be to replace https://github.com/OpenBagTwo/MarketWatch/blob/9ff71afe656fdee5b829652634f6496695ca258b/post_generator.py#L196

with:

    "tags" :  [article["pillarName"]] if "pillarName" in article else [],

but the concern is that if this field is ever legitimately renamed, then no articles will have tags from then on.

I suggest looking into which articles don't have pillarNames—it's quite possible that they're not something I want to be pulling in the first place (in which case get_random_article should be rerun).

Contributor Guide