-
Notifications
You must be signed in to change notification settings - Fork 828
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
tpilkati
wants to merge
2
commits into
GeneralMills:master
Choose a base branch
from
tpilkati:tpilkati-no-keywords-restriction
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ def _get_data(self, url, method=GET_METHOD, trim_chars=0, **kwargs): | |
'response with code {0}.'.format(response.status_code), | ||
response=response) | ||
|
||
def build_payload(self, kw_list, cat=0, timeframe='today 5-y', geo='', | ||
def build_payload(self, kw_list = [], cat=0, timeframe='today 5-y', geo='', | ||
gprop=''): | ||
"""Create the payload for related queries, interest over time and interest by region""" | ||
if gprop not in ['', 'images', 'news', 'youtube', 'froogle']: | ||
|
@@ -155,10 +155,15 @@ def build_payload(self, kw_list, cat=0, timeframe='today 5-y', geo='', | |
'req': {'comparisonItem': [], 'category': cat, 'property': gprop} | ||
} | ||
|
||
# build out json for each keyword | ||
for kw in self.kw_list: | ||
keyword_payload = {'keyword': kw, 'time': timeframe, | ||
'geo': self.geo} | ||
# build out json for each keyword if there are keywords | ||
if len(kw_list) > 0: | ||
for kw in self.kw_list: | ||
keyword_payload = {'keyword': kw, 'time': timeframe, | ||
'geo': self.geo} | ||
self.token_payload['req']['comparisonItem'].append(keyword_payload) | ||
# build out json if there are no keywords | ||
else: | ||
keyword_payload = {'keyword': '', 'time': timeframe, 'geo': self.geo} | ||
self.token_payload['req']['comparisonItem'].append(keyword_payload) | ||
# requests will mangle this if it is not a string | ||
self.token_payload['req'] = json.dumps(self.token_payload['req']) | ||
|
@@ -307,9 +312,6 @@ def related_topics(self): | |
related_payload = dict() | ||
result_dict = dict() | ||
for request_json in self.related_topics_widget_list: | ||
# ensure we know which keyword we are looking at rather than relying on order | ||
kw = request_json['request']['restriction'][ | ||
'complexKeywordsRestriction']['keyword'][0]['value'] | ||
# convert to string as requests will mangle | ||
related_payload['req'] = json.dumps(request_json['request']) | ||
related_payload['token'] = request_json['token'] | ||
|
@@ -343,7 +345,7 @@ def related_topics(self): | |
# in case no rising topics are found, the lines above will throw a KeyError | ||
df_rising = None | ||
|
||
result_dict[kw] = {'rising': df_rising, 'top': df_top} | ||
result_dict = {'rising': df_rising, 'top': df_top} | ||
return result_dict | ||
|
||
def related_queries(self): | ||
|
@@ -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 | ||
kw = request_json['request']['restriction'][ | ||
'complexKeywordsRestriction']['keyword'][0]['value'] | ||
# convert to string as requests will mangle | ||
related_payload['req'] = json.dumps(request_json['request']) | ||
related_payload['token'] = request_json['token'] | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
return result_dict | ||
|
||
def trending_searches(self, pn='united_states'): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}