-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgoogleTrends.py
More file actions
80 lines (55 loc) · 2.54 KB
/
googleTrends.py
File metadata and controls
80 lines (55 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from pytrends.request import TrendReq
import json
import pandas as pd
pytrend = TrendReq()
category = False
pd.set_option('display.expand_frame_repr', False)
pd.set_option('max_colwidth', 800)
# Real Time
realtimeTrends = pytrend.trending_realtime(cat='all', geo='US')
print(realtimeTrends.to_string())
# Treding daily
dailyTrends = pytrend.top_daily(geo='US')
print(dailyTrends.to_string())
# Create payload and capture API tokens. Extract You Tube trends from last 30 days
pytrend = TrendReq()
pytrend.build_payload(kw_list=[], gprop='youtube', timeframe='today 1-m')
# Related Topics, returns a dictionary of dataframes
related_topics_dict = pytrend.related_topics()
print(related_topics_dict)
# Related Queries, returns a dictionary of dataframes
related_queries_dict = pytrend.related_queries()
print(related_queries_dict)
# Create payload and capture API tokens. Only needed for interest_over_time(), interest_by_region() & related_queries()
pytrend = TrendReq()
keys = ["the top"]
pytrend.build_payload(kw_list=keys, cat=0, geo='', timeframe='now 7-d')
if category:
categories = pytrend.categories()
with open('categories.json', 'w') as outfile:
json.dump(categories, outfile, indent=2)
interest_by_region_df = pytrend.interest_by_region(resolution="COUNTRY")
print(interest_by_region_df.sort_values(keys[0], ascending=False).head(5))
# Related Topics, returns a dictionary of dataframes
related_topics_dict = pytrend.related_topics()
print(related_topics_dict[keys[0]]["top"].to_string())
print(related_topics_dict[keys[0]]["rising"].to_string())
# Related Queries, returns a dictionary of dataframes
related_queries_dict = pytrend.related_queries()
print(related_queries_dict[keys[0]]["top"].to_string())
print(related_queries_dict[keys[0]]["rising"].to_string())
#historical interest
hist = pytrend.get_historical_interest(keys, year_start=2019)
print(hist.to_string())
# Get Google Keyword Suggestions
suggestions_dict = pytrend.suggestions(keyword="Pacers vs Celtics")
print(suggestions_dict)
pytrend.build_payload(kw_list=[], cat=1072, geo='', gprop="youtube", timeframe='today 1-m')
# Related Topics, returns a dictionary of dataframes
related_topics_dict = pytrend.related_topics()
print(related_topics_dict[list(related_topics_dict)[0]]["top"])
print(related_topics_dict[list(related_topics_dict)[0]]["rising"])
# Related Queries, returns a dictionary of dataframes
related_queries_dict = pytrend.related_queries()
print(related_queries_dict[list(related_queries_dict)[0]]["top"])
print(related_queries_dict[list(related_queries_dict)[0]]["rising"])