Skip to content

Commit

Permalink
v0.9
Browse files Browse the repository at this point in the history
Fixed program crash when google trends is unavailable
  • Loading branch information
deedy5 authored Aug 30, 2021
1 parent e95f4f2 commit 72d05f4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fake_traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from google_trends import realtime_trends


__version__ = 0.8
__version__ = 0.9

THREADS = 1
MIN_WAIT = 1
Expand All @@ -34,8 +34,13 @@ def debug_print(*agrs, **kwargs):
print(*agrs, **kwargs)

def real_trends(country='US', language='en-US'):
trends = realtime_trends(country=country, language=language, category='h', num_results=20)
return trends
while True:
try:
trends = realtime_trends(country=country, language=language, category='h', num_results=20)
return trends
except:
print(f'Google trends error. Sleep 25-35 sec')
sleep(uniform(25, 35))

def get_url(url):
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"}
Expand Down

0 comments on commit 72d05f4

Please sign in to comment.