123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- 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':'餐飲業補助','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://finance.ettoday.net/news/2252097','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()
|