Skip to content

Instantly share code, notes, and snippets.

@pixyfox
Last active November 12, 2022 14:08
Show Gist options
  • Save pixyfox/66a26833da0fbad1fb073ab4400cdb4d to your computer and use it in GitHub Desktop.
Save pixyfox/66a26833da0fbad1fb073ab4400cdb4d to your computer and use it in GitHub Desktop.
# Perform searches
wait = 6 # in seconds
print('Number of queries to do: ', len(keywords) * len(geo))
# Prepare containers
trends = dict.fromkeys(geo)
errors_list = []
cnt = 1
# Start loops
for g in geo:
trends[g] = {}
for k in keywords:
try:
time.sleep(wait)
pytrends.build_payload([k], timeframe='all', geo=g, gprop='')
trends[g][k] = pytrends.interest_over_time()[k]
#print(cnt, 'Success: ', g, k)
except:
print(cnt, ') Error: ', g, ' & ', k)
errors_list.append([g,k])
cnt+=1
print('\nDone -', len(errors_list), 'errors left')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment