|
@@ -79,6 +79,9 @@ def get_idea():
|
|
|
result+=str(c['query'])+"\n"
|
|
|
return result
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def get_hotkeys_ls(past=False):
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/yodb?charset=utf8mb4')
|
|
|
now = ''
|
|
@@ -98,6 +101,7 @@ def get_hotkeys_ls(past=False):
|
|
|
ls.append(row['ts_word'])
|
|
|
ls = list(dict.fromkeys(ls))
|
|
|
return ls
|
|
|
+
|
|
|
def get_hotkeys(past=False):
|
|
|
js=json.load(open('test.json','r',encoding='utf-8'))
|
|
|
keys = get_hotkeys_ls(past)
|
|
@@ -194,7 +198,65 @@ def flex_test():
|
|
|
]
|
|
|
js['body']['contents'] = js['body']['contents'] + [row_dict]
|
|
|
return js
|
|
|
-
|
|
|
+def make_bubble():
|
|
|
+ box_dict = {
|
|
|
+ "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": "text",
|
|
|
+ "text": "熱門搜尋關鍵字",
|
|
|
+ "size": "xl",
|
|
|
+ "weight": "bold",
|
|
|
+ "align": "center"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return box_dict
|
|
|
+
|
|
|
+def make_box(num, content):
|
|
|
+ row_dict = {}
|
|
|
+ row_dict['type'] = 'box'
|
|
|
+ row_dict['layout'] = 'baseline'
|
|
|
+ row_dict['contents']= [
|
|
|
+ {
|
|
|
+ "type": "text",
|
|
|
+ "text": "第"+str(num)+"名次",
|
|
|
+ "size": "sm",
|
|
|
+ "color": "#aaaaaa",
|
|
|
+ "flex": 1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "type": "text",
|
|
|
+ "text": "hello, world"+str(1),
|
|
|
+ "flex": 5,
|
|
|
+ "weight": "regular"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ return row_dict
|
|
|
+
|
|
|
+def make_carousel():
|
|
|
+ carousel_dict = {"type": "carousel","contents": []}
|
|
|
+ carousel_idx = -1
|
|
|
+ for i in range(26):
|
|
|
+ if i%12 ==0:
|
|
|
+ carousel_dict['contents'] = carousel_dict['contents']+[make_bubble()]
|
|
|
+ carousel_idx+=1
|
|
|
+
|
|
|
+ carousel_dict['contents'][carousel_idx]['body']['contents'] += [make_box(i,'data'+str(i))]
|
|
|
+
|
|
|
+ return carousel_dict
|
|
|
|
|
|
@handler.add(FollowEvent)
|
|
|
def handle_follow(event):
|
|
@@ -259,6 +321,7 @@ def message_text(event):
|
|
|
|
|
|
if event.message.text=='熱門關鍵字':
|
|
|
js = get_hotkeys(False)
|
|
|
+ js = make_carousel()
|
|
|
line_bot_api.reply_message(event.reply_token, FlexSendMessage('ChoozMo',js))
|
|
|
return
|
|
|
|