|
@@ -0,0 +1,22 @@
|
|
|
+# Since pytrends is returning a DataFrame object, we need pandas:
|
|
|
+import pandas as pd
|
|
|
+# Import of pytrends (needs to be pip installed first):
|
|
|
+from pytrends.request import TrendReq
|
|
|
+import dataset
|
|
|
+
|
|
|
+db = dataset.connect('mysql://choozmo:pAssw0rd@139.162.121.30:33306/marketing_cal?charset=utf8mb4')
|
|
|
+table=db['trends_tests']
|
|
|
+
|
|
|
+
|
|
|
+pytrends = TrendReq(hl='zh-TW')
|
|
|
+kw='婚禮'
|
|
|
+
|
|
|
+pytrends.build_payload([kw], cat=0, timeframe='today 5-y', geo='', gprop='')
|
|
|
+
|
|
|
+search_df=pytrends.interest_over_time()
|
|
|
+for dt, row in search_df.T.iteritems():
|
|
|
+ table.insert({'kw':kw,'dt':dt,'popularity':int(row[0]) })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|