pytrends icon indicating copy to clipboard operation
pytrends copied to clipboard

Allow multiple timeframes for different keywords on interest_over_time

Open magico opened this issue 2 years ago • 1 comments

In Google Trends you can compare two different timeframes for two completely different keywords. For example: https://trends.google.com/trends/explore?date=2022-03-28%202022-04-01,2021-04-26%202021-04-30&geo=US,US&q=oscars%202022,oscars%202021

Currently you can't do this in pytrends. If one calculates both periods separately, the scales are off.

Solution I propose that for the timeframe parameter to accept an array of dates. It would then pair kw_list[0] with timeframe[0] and so on.

I someone has a more elegant solution please let me know 😄

magico avatar Oct 07 '22 03:10 magico

Looking into it a bit more, this would use the multirange endpoint. For example:

https://trends.google.com/trends/api/widgetdata/multirange?hl=en-US&tz=420&req={"resolution":"DAY","comparisonItem":[{"geo":{"country":"US"},"time":"2022-09-04 2022-09-10","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"oscars"}]}},{"geo":{"country":"US"},"time":"2022-09-18 2022-09-24","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"oscars"}]}}],"requestOptions":{"property":"","backend":"IZG","category":0},"userConfig":{"userType":"USER_TYPE_LEGIT_USER"}}&token=TOKEN&tz=420

magico avatar Oct 12 '22 17:10 magico