Kaynağa Gözat

return list only

ming 3 yıl önce
ebeveyn
işleme
f3eaf816c4
1 değiştirilmiş dosya ile 39 ekleme ve 28 silme
  1. 39 28
      newbot.py

+ 39 - 28
newbot.py

@@ -79,6 +79,26 @@ def get_idea():
         result+=str(c['query'])+"\n"
     return result
 
+def get_hotkeys(past=false):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/yodb?charset=utf8mb4')
+    now = ''
+    if past:
+        now = datetime.datetime.now()
+    else
+        now = datetime.datetime.now()-datetime.timedelta(days=1)
+    now_start = now.strftime("%Y-%m-%d 00:00:00")
+    now_end = now.strftime("%Y-%m-%d 23:59:59")
+    sqls = 'SELECT * FROM trending_searches WHERE "'+now_end+'">= ts_date and "'+now_start+'"<=ts_date ORDER BY ts_date DESC'
+    ls = []
+    for row in db.query(sqls):
+        ls.append(row['ts_word'])
+    ls = list(dict.fromkeys(ls))
+    out_result = ''
+    num = 1
+    for w in ls:
+        out_result = out_result + "第"+str(num)+"名 :"+ w+'\n'
+        num = num + 1
+    return out_result
 
 
 @app.get("/aws")
@@ -163,6 +183,17 @@ def message_text(event):
             event.reply_token,
             TextSendMessage(text=get_idea()))
         return
+    ############################
+    if event.message.text == 'q_aws':
+        line_bot_api.reply_message(
+            event.reply_token,[TextSendMessage(text=get_aws()),TextSendMessage(text='完整報告: https://api.ptt.cx:5443/aws')])
+                    
+        return
+    if event.message.text == 'q_aws':
+        line_bot_api.reply_message(
+            event.reply_token,[TextSendMessage(text=get_aws()),TextSendMessage(text='完整報告: https://api.ptt.cx:5443/aws')])
+                    
+        return
 
 
 
@@ -174,40 +205,14 @@ def message_text(event):
         return
         
     if event.message.text=='熱門關鍵字':
-        db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/yodb?charset=utf8mb4')
-        now = datetime.datetime.now()
-        now_start = now.strftime("%Y-%m-%d 00:00:00")
-        now_end = now.strftime("%Y-%m-%d 23:59:59")
-        sqls = 'SELECT * FROM trending_searches WHERE "'+now_end+'">= ts_date and "'+now_start+'"<=ts_date ORDER BY ts_date DESC'
-        ls = []
-        for row in db.query(sqls):
-            ls.append(row['ts_word'])
-        ls = list(dict.fromkeys(ls))
-        out_result = ''
-        num = 1
-        for w in ls:
-            out_result = out_result + "第"+str(num)+"名 :"+ w+'\n'
-            num = num + 1
+        out_result = get_hotkeys(false)
             
         line_bot_api.reply_message(
             event.reply_token,
             TextSendMessage(text=out_result))
             
     if event.message.text=='關鍵字歷史走勢':
-        db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/yodb?charset=utf8mb4')
-        now = datetime.datetime.now()-datetime.timedelta(days=1)
-        now_start = now.strftime("%Y-%m-%d 00:00:00")
-        now_end = now.strftime("%Y-%m-%d 23:59:59")
-        sqls = 'SELECT * FROM trending_searches WHERE "'+now_end+'">= ts_date and "'+now_start+'"<=ts_date ORDER BY ts_date DESC'
-        ls = []
-        for row in db.query(sqls):
-            ls.append(row['ts_word'])
-        ls = list(dict.fromkeys(ls))
-        out_result = ''
-        num = 1
-        for w in ls:
-            out_result = out_result + "第"+str(num)+"名 :"+ w+'\n'
-            num = num + 1
+        out_result = get_hotkeys(true)
             
         line_bot_api.reply_message(
             event.reply_token,
@@ -237,6 +242,12 @@ def message_text(event):
                                 QuickReplyButton(
                                     action=MessageAction(label="關聯字", text="seo")
                                 ),
+                                QuickReplyButton(
+                                    action=MessageAction(label="熱門關鍵字", text="seo")
+                                ),
+                                QuickReplyButton(
+                                    action=MessageAction(label="關鍵字歷史走勢", text="seo")
+                                ),
 
                             ])))
     else: