epfl-dlab / GoogleTrendsAnchorBank

Google Trends, made easy.
MIT License
101 stars 22 forks source link

US state or region level geo tags in pytrends_config? #4

Closed LizMcQuillan closed 4 years ago

LizMcQuillan commented 4 years ago

Is there a way to pass a more granular geo: argument than the country level? Specifically, at the US state ("New York", "Kentucky", etc) or regional ("Northeast", "West", etc) levels?

Looking through your source code it looks like the answer is no (geo (str) - containing the two-letter ISO code of the country, e.g. "US", or "" empty string for global).

manoelhortaribeiro commented 4 years ago

Hey Liz! Indeed I feel that right now it is not (yet) supported, yet, I feel this can be made possible with minor changes @GorjanP, can you have a look at that?

GorjanP commented 4 years ago

Hi Liz! To directly address your question about US state level queries, it is indeed supported! The underlying Google Trends API is PyTrends, and its documentation states:

More detail available for States/Provinces by specifying additional abbreviations. For example: Alabama would be 'US-AL'

I am not sure if the Google Trends documentation has an explicit list, but one way to figure it out is to type a query into Google Trends and when choosing the region click the little arrow next to it to see the available sub-regions (see image).

ex

After this notice that the URL in your browser window contains the abbreviation. For example If I choose Austria -> Vienna, the URL is https://trends.google.com/trends/explore?geo=AT-9&q=Example%20query and the geo code is there - AT-9. You just have to set it via theset_options method or if you're using the command line interface through gtab-set-options script.

N.B. The PyTrends official documentation explicitly states "two letter country abbreviation", hence why the G-TAB documentation does the same. To clear any future potential confusion I will try to extract all available regions from the Google Trends website and list them in the documentation. Thanks for noticing this!

LizMcQuillan commented 4 years ago

Thanks! It would be helpful to add a line in your docs saying that you support sub-country level queries - even with a link to the pytrends docs that govern the naming conventions.