pytrends
pytrends copied to clipboard
Allow multiple timeframes for different keywords on interest_over_time
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 😄
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