import opengraph import redis from jinja2 import Environment, BaseLoader import traceback bubble3=""" { "type": "bubble", "direction": "ltr", "header": { "type": "box", "layout": "vertical", "contents": [ { "type": "box", "layout": "horizontal", "action": { "type": "uri", "uri": "https://page.line.me/choozmo" }, "width": "100%", "contents": [ { "type": "text", "text": "今日熱搜", "align": "start", "contents": [] }, { "type": "image", "url": "https://i.imgur.com/wQbJeGc.png", "align": "end", "aspectRatio": "4:1", "aspectMode": "cover" } ] } ] }, "body": { "type": "box", "layout": "vertical", "paddingAll": "0px", "width": "100%", "backgroundColor": "#000000FF", "action": { "type": "uri", "uri": "{{ qlink }}" }, "contents": [ { "type": "box", "layout": "vertical", "contents": [ { "type": "image", "url": "{{ imgurl }}", "size": "full", "aspectMode": "cover" }, { "type": "box", "layout": "vertical", "position": "absolute", "offsetBottom": "0px", "width": "100%", "height": "90px", "backgroundColor": "#9C8E7ECC", "contents": [ { "type": "text", "text": "{{ imgtitle }}", "color": "#FFFFFFFF", "align": "start", "wrap": true, "contents": [] } ] } ] }, { "type": "box", "layout": "horizontal", "position": "absolute", "offsetTop": "10px", "offsetStart": "5px", "width": "100px", "borderWidth": "1px", "backgroundColor": "#898CDFFF", "cornerRadius": "5px", "contents": [ { "type": "text", "text": "{{title}}", "color": "#FFFFFFFF", "align": "center", "contents": [] } ] } ] }, "footer": { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "相關關鍵字", "contents": [] }, { "type": "separator" }, { "type": "box", "layout": "horizontal", "contents": [ { "type": "text", "text": "{{K1}}", "contents": [] }, { "type": "text", "text": "{{K2}}", "contents": [] } ] }, { "type": "box", "layout": "horizontal", "contents": [ { "type": "text", "text": "{{K3}}", "contents": [] }, { "type": "text", "text": "{{K4}}", "contents": [] } ] } ] } } """ data3_begin=""" { "type": "carousel", "contents": [ """ data3_end=""" ] } """ import dataset import json import sys result_lst=[] result_lst.append({'title':'經濟部助餐飲業抗疫 補助行銷最高10萬','imgurl':'https://s.yimg.com/ny/api/res/1.2/9YvKYByhEh1BZ7T4I.r.2A--/YXBwaWQ9aGlnaGxhbmRlcjt3PTk2MDtoPTU0MDtjZj13ZWJw/https://s.yimg.com/uu/api/res/1.2/x61AeEz53wkYlI70v5o7gQ--~B/aD01NzY7dz0xMDI0O2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/zh-tw/ftvn.com.tw/8d2b186dec3629f6a7af920dbbe5a48b','qlink':'https://tw.news.yahoo.com/%E7%B6%93%E6%BF%9F%E9%83%A8%E5%8A%A9%E9%A4%90%E9%A3%B2%E6%A5%AD%E6%8A%97%E7%96%AB-%E8%A3%9C%E5%8A%A9%E8%A1%8C%E9%8A%B7%E6%9C%80%E9%AB%9810%E8%90%AC-101819556.html','imgtitle':'經濟部助餐飲業抗疫 補助行銷最高10萬','K1':'餐飲 業者','K2':'行銷 補助','K3':'經濟部 餐飲業 補助','K4':'餐飲業 補助'}) r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9') rtemplate = Environment(loader=BaseLoader).from_string(bubble3) result="" for r2 in result_lst: # r3 = rtemplate.render({'title':title,'imgurl':imgurl,'qlink':qlink,'imgtitle':imgtitle,'K1':k1,'K2':k2,'K3':k3,'K4':k4}) r3 = rtemplate.render(r2) result+=r3 result+=',' result=result[:-1] final_result=data3_begin+result+data3_end full_result='{"title":"今日熱搜關鍵字","data":'+final_result+'}' #final_result=data3_begin+result+data3_end print(final_result) #r.set('btn_data',final_result) r.set('liff3',full_result) #r.set('btn_data',data2) sys.exit()