alone_redis_set.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import opengraph
  2. import redis
  3. from jinja2 import Environment, BaseLoader
  4. import traceback
  5. bubble3="""
  6. {
  7. "type": "bubble",
  8. "direction": "ltr",
  9. "header": {
  10. "type": "box",
  11. "layout": "vertical",
  12. "contents": [
  13. {
  14. "type": "box",
  15. "layout": "horizontal",
  16. "action": {
  17. "type": "uri",
  18. "uri": "https://page.line.me/choozmo"
  19. },
  20. "width": "100%",
  21. "contents": [
  22. {
  23. "type": "text",
  24. "text": "點我申請",
  25. "align": "start",
  26. "contents": []
  27. },
  28. {
  29. "type": "image",
  30. "url": "https://i.imgur.com/wQbJeGc.png",
  31. "align": "end",
  32. "aspectRatio": "4:1",
  33. "aspectMode": "cover"
  34. }
  35. ]
  36. }
  37. ]
  38. },
  39. "body": {
  40. "type": "box",
  41. "layout": "vertical",
  42. "paddingAll": "0px",
  43. "width": "100%",
  44. "backgroundColor": "#000000FF",
  45. "action": {
  46. "type": "uri",
  47. "uri": "{{ qlink }}"
  48. },
  49. "contents": [
  50. {
  51. "type": "box",
  52. "layout": "vertical",
  53. "contents": [
  54. {
  55. "type": "image",
  56. "url": "{{ imgurl }}",
  57. "size": "full",
  58. "aspectMode": "cover"
  59. },
  60. {
  61. "type": "box",
  62. "layout": "vertical",
  63. "position": "absolute",
  64. "offsetBottom": "0px",
  65. "width": "100%",
  66. "height": "90px",
  67. "backgroundColor": "#9C8E7ECC",
  68. "contents": [
  69. {
  70. "type": "text",
  71. "text": "{{ imgtitle }}",
  72. "color": "#FFFFFFFF",
  73. "align": "start",
  74. "wrap": true,
  75. "contents": []
  76. }
  77. ]
  78. }
  79. ]
  80. },
  81. {
  82. "type": "box",
  83. "layout": "horizontal",
  84. "position": "absolute",
  85. "offsetTop": "10px",
  86. "offsetStart": "5px",
  87. "width": "100px",
  88. "borderWidth": "1px",
  89. "backgroundColor": "#898CDFFF",
  90. "cornerRadius": "5px",
  91. "contents": [
  92. {
  93. "type": "text",
  94. "text": "{{title}}",
  95. "color": "#FFFFFFFF",
  96. "align": "center",
  97. "contents": []
  98. }
  99. ]
  100. }
  101. ]
  102. },
  103. "footer": {
  104. "type": "box",
  105. "layout": "vertical",
  106. "contents": [
  107. {
  108. "type": "text",
  109. "text": "相關關鍵字",
  110. "contents": []
  111. },
  112. {
  113. "type": "separator"
  114. },
  115. {
  116. "type": "box",
  117. "layout": "horizontal",
  118. "contents": [
  119. {
  120. "type": "text",
  121. "text": "{{K1}}",
  122. "contents": []
  123. },
  124. {
  125. "type": "text",
  126. "text": "{{K2}}",
  127. "contents": []
  128. }
  129. ]
  130. },
  131. {
  132. "type": "box",
  133. "layout": "horizontal",
  134. "contents": [
  135. {
  136. "type": "text",
  137. "text": "{{K3}}",
  138. "contents": []
  139. },
  140. {
  141. "type": "text",
  142. "text": "{{K4}}",
  143. "contents": []
  144. }
  145. ]
  146. }
  147. ]
  148. }
  149. }
  150. """
  151. data3_begin="""
  152. {
  153. "type": "carousel",
  154. "contents": [
  155. """
  156. data3_end="""
  157. ]
  158. }
  159. """
  160. import dataset
  161. import json
  162. import sys
  163. result_lst=[]
  164. 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':'餐飲業 補助'})
  165. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  166. rtemplate = Environment(loader=BaseLoader).from_string(bubble3)
  167. result=""
  168. for r2 in result_lst:
  169. # r3 = rtemplate.render({'title':title,'imgurl':imgurl,'qlink':qlink,'imgtitle':imgtitle,'K1':k1,'K2':k2,'K3':k3,'K4':k4})
  170. r3 = rtemplate.render(r2)
  171. result+=r3
  172. result+=','
  173. result=result[:-1]
  174. final_result=data3_begin+result+data3_end
  175. full_result='{"title":"申請餐飲補助","data":'+final_result+'}'
  176. #final_result=data3_begin+result+data3_end
  177. print(final_result)
  178. #r.set('btn_data',final_result)
  179. r.set('liff3',full_result)
  180. #r.set('btn_data',data2)
  181. sys.exit()