ming vor 4 Jahren
Ursprung
Commit
f3591d2d60
2 geänderte Dateien mit 30 neuen und 33 gelöschten Zeilen
  1. 30 14
      newbot.py
  2. 0 19
      test.json

+ 30 - 14
newbot.py

@@ -96,13 +96,8 @@ def get_hotkeys(past=False):
     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
+    #ls = list(dict.fromkeys(ls))
+    return ls
 
 
 @app.get("/aws")
@@ -160,10 +155,10 @@ def flex_test():
         row_dict['contents']= [
             {
                 "type": "text",
-                "text": "第"+str(i)+"名",
+                "text": "第"+str(i)+"名",
                 "size": "sm",
                 "color": "#aaaaaa",
-                "flex": 1
+                "flex": 2
             },
             {
                 "type": "text",
@@ -240,11 +235,32 @@ def message_text(event):
             
 
     if event.message.text=='熱門關鍵字':
-        out_result = get_hotkeys(False)
-            
-        line_bot_api.reply_message(
-            event.reply_token,
-            TextSendMessage(text=out_result))
+        js=json.load(open('test.json','r',encoding='utf-8'))
+        keys = get_hotkeys(past=False)
+        num = 1
+        for k in keys:
+            row_dict = {}
+            row_dict['type'] = 'box'
+            row_dict['layout'] = 'baseline'
+            row_dict['contents']= [
+                {
+                    "type": "text",
+                    "text": "第"+str(num)+"名",
+                    "size": "sm",
+                    "color": "#aaaaaa",
+                    "flex": 2
+                },
+                {
+                    "type": "text",
+                    "text": k,
+                    "flex": 5,
+                    "weight": "regular"
+                }
+                ]
+            num = num + 1
+            js['body']['contents'] = js['body']['contents'] + [row_dict]
+        line_bot_api.reply_message(event.reply_token, FlexSendMessage('ChoozMo',FlexMessage))
+        return
             
     if event.message.text=='關鍵字歷史走勢':
         out_result = get_hotkeys(True)

+ 0 - 19
test.json

@@ -17,25 +17,6 @@
         "text": "熱門搜尋關鍵字",
         "size": "xl",
         "weight": "bold"
-      },
-      {
-        "type": "box",
-        "layout": "baseline",
-        "contents": [
-          {
-            "type": "text",
-            "text": "hello",
-            "size": "sm",
-            "color": "#aaaaaa",
-            "flex": 1
-          },
-          {
-            "type": "text",
-            "text": "hello, world",
-            "flex": 5,
-            "weight": "regular"
-          }
-        ]
       }
     ]
   }