alex9smith / gdelt-doc-api

A Python client for the GDELT 2.0 Doc API
MIT License
91 stars 20 forks source link

Queries using multi-repeat OR fail #15

Closed alex9smith closed 2 years ago

alex9smith commented 2 years ago

Queries using the multi_repeat filter with OR as the method always fail with the same error message shown in #11.

An example:

Python 3.9.4 (default, May 10 2021, 13:51:57)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from gdeltdoc import Filters, near, repeat, GdeltDoc, multi_repeat
   ...:
   ...: f = Filters(
   ...:     start_date = "2017-05-01",
   ...:     end_date = "2022-02-02",
   ...:     num_records = 250,
   ...:     keyword = "low carbon",
   ...:     near = near(10, 'emission', 'airport'),
   ...:     repeat = multi_repeat([(2, "airline"), (3, "airport")], "OR")
   ...: )
   ...: gd = GdeltDoc()
   ...:
   ...: # Search for articles matching the filters
   ...: articles = gd.article_search(f)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [1], in <cell line: 14>()
     11 gd = GdeltDoc()
     13 # Search for articles matching the filters
---> 14 articles = gd.article_search(f)

File ~/code/gdelt-doc-api/gdeltdoc/api_client.py:79, in GdeltDoc.article_search(self, filters)
     64 """
     65 Make a query against the `ArtList` API to return a DataFrame of news articles that
     66 match the supplied filters.
   (...)
     76     A pandas DataFrame of the articles returned from the API.
     77 """
     78 articles = self._query("artlist", filters.query_string)
---> 79 if "articles" in articles:
     80     return pd.DataFrame(articles["articles"])
     81 else:

TypeError: argument of type 'int' is not iterable

Raised by @priolap as a comment here: https://github.com/alex9smith/gdelt-doc-api/pull/12#issuecomment-1134502338

alex9smith commented 2 years ago

FYI @priolap this is now fixed (see #16). If you update to 1.3.3 your queries will work

priolap commented 2 years ago

it works. Thank you!