Browse Source

return list only

ming 3 năm trước cách đây
mục cha
commit
dc519feb04
1 tập tin đã thay đổi với 12 bổ sung1 xóa
  1. 12 1
      newbot.py

+ 12 - 1
newbot.py

@@ -10,6 +10,7 @@ import datetime
 from fastapi.responses import HTMLResponse
 from fastapi.responses import HTMLResponse
 #
 #
 
 
+
 from linebot.models import (
 from linebot.models import (
     MessageEvent, TextMessage, TextSendMessage,
     MessageEvent, TextMessage, TextSendMessage,
     SourceUser, SourceGroup, SourceRoom,
     SourceUser, SourceGroup, SourceRoom,
@@ -173,9 +174,19 @@ def message_text(event):
         return
         return
         
         
     if event.message.text=='熱門關鍵字':
     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(
         line_bot_api.reply_message(
             event.reply_token,
             event.reply_token,
-            TextSendMessage(text='最欣賞ChoozMo團隊說ooooK的人!!'))
+            TextSendMessage(text=ls))
+            
     if event.message.text=='關鍵字歷史走勢':
     if event.message.text=='關鍵字歷史走勢':
         line_bot_api.reply_message(
         line_bot_api.reply_message(
             event.reply_token,
             event.reply_token,