Pārlūkot izejas kodu

dynamic json test

ming 4 gadi atpakaļ
vecāks
revīzija
2b82386c13
2 mainītis faili ar 38 papildinājumiem un 12 dzēšanām
  1. 20 0
      newbot.py
  2. 18 12
      test.json

+ 20 - 0
newbot.py

@@ -153,6 +153,26 @@ def get_news_by_kw(keyword):
 
 def flex_test():
     js=json.load(open('test.json','r',encoding='utf-8'))
+    for i in range(3):
+        row_dict = {}
+        row_dict['type'] = 'box'
+        row_dict['layout'] = 'baseline'
+        row_dict['contents']= [
+            {
+                "type": "text",
+                "text": "第"+str(i)+"名次",
+                "size": "sm",
+                "color": "#aaaaaa",
+                "flex": 1
+            },
+            {
+                "type": "text",
+                "text": "hello, world"+str(1),
+                "flex": 5,
+                "weight": "regular"
+            }
+            ]
+        js['body']['contents'] = js['body']['contents'] + [row_dict]
     return js
 
 

+ 18 - 12
test.json

@@ -1,21 +1,22 @@
 {
   "type": "bubble",
+  "hero": {
+    "type": "image",
+    "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_1_cafe.png",
+    "size": "full",
+    "gravity": "top",
+    "margin": "none",
+    "aspectRatio": "20:13"
+  },
   "body": {
     "type": "box",
     "layout": "vertical",
     "contents": [
-      {
-        "type": "image",
-        "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_1_cafe.png",
-        "size": "full",
-        "margin": "none",
-        "align": "start",
-        "gravity": "top",
-        "position": "relative"
-      },
       {
         "type": "text",
-        "text": "hello, world"
+        "text": "熱門搜尋關鍵字",
+        "size": "xl",
+        "weight": "bold"
       },
       {
         "type": "box",
@@ -23,11 +24,16 @@
         "contents": [
           {
             "type": "text",
-            "text": "hello, world"
+            "text": "hello",
+            "size": "sm",
+            "color": "#aaaaaa",
+            "flex": 1
           },
           {
             "type": "text",
-            "text": "hello, world"
+            "text": "hello, world",
+            "flex": 5,
+            "weight": "regular"
           }
         ]
       }