Explorar el Código

return list only

ming hace 3 años
padre
commit
bc27b30684
Se han modificado 1 ficheros con 17 adiciones y 2 borrados
  1. 17 2
      newbot.py

+ 17 - 2
newbot.py

@@ -186,7 +186,7 @@ def message_text(event):
         out_result = ''
         num = 1
         for w in ls:
-            out_result = "第"+str(num)+"名 :"+out_result + w+'\n'
+            out_result = out_result + "第"+str(num)+"名 :"+ w+'\n'
             num = num + 1
             
         line_bot_api.reply_message(
@@ -194,9 +194,24 @@ def message_text(event):
             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.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
+            
         line_bot_api.reply_message(
             event.reply_token,
-            TextSendMessage(text='最欣賞ChoozMo團隊說OkkkkK的人!!'))
+            TextSendMessage(text=out_result))
             
     if event.message.text == '叫':
         line_bot_api.reply_message(