Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed keywords restriction in payloads #414

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tpilkati
Copy link

removed keywords restriction in order to look for most searched topics and queries during a certain period of time without having specified any keyword, as in:

https://trends.google.com/trends/explore?date=today%201-m&geo=US

removed keywords restriction in order to look for most searched topics and queries during a certain period of time without having specified any keyword, as in:

https://trends.google.com/trends/explore?date=today%201-m&geo=US
@tpilkati
Copy link
Author

sometimes we need to look for top searched topics and top searched queries during a specific period of time, this is possible in:

https://trends.google.com/trends/explore?date=today%201-m&geo=US

I changed the build_pailoads for default keywords = empty list when there is no keyword parameter so that it is possible to see related_topics and related_queries when there isn't any keyword specified

@@ -390,7 +389,7 @@ def related_queries(self):
# in case no rising queries are found, the lines above will throw a KeyError
rising_df = None

result_dict[kw] = {'top': top_df, 'rising': rising_df}
result_dict = {'top': top_df, 'rising': rising_df}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're fundamentally changing the form of what gets returned, even for conventional keyword-bearing use-cases.

@@ -356,9 +358,6 @@ def related_queries(self):
related_payload = dict()
result_dict = dict()
for request_json in self.related_queries_widget_list:
# ensure we know which keyword we are looking at rather than relying on order
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality doesn't seem to be replaced.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, you're right I was so focused on getting the result without keywords I didn't check the alternatives. Now without keywords is just optional, when there are keywords nothing changes:

https://github.com/tpilkati/pytrends/commit/6ca4733c1a23e45b6cfc084381466dcbd89e3d2b

if len(self.kw_list) > 0:
# ensure we know which keyword we are looking at rather than relying on order
kw = request_json['request']['restriction']['complexKeywordsRestriction']['keyword'][0]['value']
result_dict[kw] = {'rising': df_rising, 'top': df_top}
else:
result_dict = {'rising': df_rising, 'top': df_top}

added related_topics and related_queries with no keywords as optional
@BAG-OF-CHIPS-XX
Copy link

Not sure if this is still an issue. But, I figured out how to fix the errors related to blank seed keywords. just replace lines 367&377 in request.py:
kw = request_json['request']['restriction']['complexKeywordsRestriction']['keyword'][0]['value']
with this:
try:
kw = request_json['request']['restriction'][
'complexKeywordsRestriction']['keyword'][0]['value']
else:
# this accounts for blank seed keyword
kw=''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants