Przeglądaj źródła

return list only

ming 3 lat temu
rodzic
commit
dc519feb04
1 zmienionych plików z 12 dodań i 1 usunięć
  1. 12 1
      newbot.py

+ 12 - 1
newbot.py

@@ -10,6 +10,7 @@ import datetime
 from fastapi.responses import HTMLResponse
 #
 
+
 from linebot.models import (
     MessageEvent, TextMessage, TextSendMessage,
     SourceUser, SourceGroup, SourceRoom,
@@ -173,9 +174,19 @@ def message_text(event):
         return
         
     if event.message.text=='熱門關鍵字':
+        db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/yodb?charset=utf8mb4')
+        now = datetime.now()
+        now_start = now.strftime("%d-%m-%Y 00:00:00")
+        now_end = now.strftime("%d-%m-%Y 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['tw_word'])
+            
         line_bot_api.reply_message(
             event.reply_token,
-            TextSendMessage(text='最欣賞ChoozMo團隊說ooooK的人!!'))
+            TextSendMessage(text=ls))
+            
     if event.message.text=='關鍵字歷史走勢':
         line_bot_api.reply_message(
             event.reply_token,