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.append({'title':title,'imgurl':imgurl,'qlink':qlink,'imgtitle':imgtitle,'K1':k1,'K2':k2,'K3':k3,'K4':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('btn_data',full_result) #r.set('btn_data',data2) sys.exit()