123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888 |
- import opengraph
- import redis
- from jinja2 import Environment, BaseLoader
- import traceback
- data="""
- {
- "type": "bubble",
- "header": {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "text",
- "text": "集仕多 ChoozMo",
- "weight": "bold",
- "size": "xl",
- "color": "#ffffff"
- },
- {
- "type": "text",
- "text": "新聞 AI 主播媒體聯播網最佳方案",
- "size": "md",
- "color": "#ffffff"
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "xxl",
- "url": "https://ppt.cc/fLP10x@.png",
- "offsetTop": "xs"
- }
- ],
- "justifyContent": "flex-end",
- "offsetStart": "255px",
- "position": "absolute",
- "offsetBottom": "20px"
- }
- ],
- "backgroundColor": "#e1642b"
- },
- "hero": {
- "type": "image",
- "url": "https://ppt.cc/fDmzAx@.png",
- "size": "full",
- "aspectRatio": "20:13",
- "action": {
- "type": "uri",
- "uri": "http://linecorp.com/"
- },
- "offsetTop": "lg"
- },
- "body": {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "text",
- "text": "圖文+影音+聯播",
- "color": "#aaaaaa",
- "size": "sm"
- },
- {
- "type": "text",
- "text": "全方位媒體曝光,一次到位!",
- "color": "#aaaaaa",
- "size": "sm"
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "md",
- "url": "https://ppt.cc/feXZPx@.png",
- "offsetTop": "xs"
- },
- {
- "type": "text",
- "text": "網路新聞圖文報導",
- "offsetStart": "md",
- "color": "#e47e4d",
- "weight": "bold"
- }
- ]
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "md",
- "url": "https://ppt.cc/feXZPx@.png",
- "offsetTop": "xs"
- },
- {
- "type": "text",
- "text": "十二家網路媒體聯播",
- "offsetStart": "md",
- "color": "#e47e4d",
- "weight": "bold"
- }
- ]
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "md",
- "url": "https://ppt.cc/feXZPx@.png",
- "offsetTop": "xs"
- },
- {
- "type": "text",
- "text": "AI 主播影音播報影片",
- "offsetStart": "md",
- "color": "#e47e4d",
- "weight": "bold"
- }
- ]
- },
- {
- "type": "box",
- "layout": "horizontal",
- "margin": "lg",
- "spacing": "sm",
- "contents": [
- {
- "type": "text",
- "text": "一次到位擁有,只要",
- "margin": "none",
- "size": "sm",
- "gravity": "center",
- "color": "#2384e3",
- "weight": "bold"
- },
- {
- "type": "text",
- "text": "$36,000",
- "size": "xxl",
- "offsetStart": "5px",
- "weight": "bold",
- "color": "#2384e3"
- }
- ],
- "backgroundColor": "#fff3ed",
- "background": {
- "type": "linearGradient",
- "angle": "0deg",
- "startColor": "#fff3ed",
- "endColor": "#ffffff"
- }
- },
- {
- "type": "text",
- "text": "不論是公司宣傳/產品發表/品牌經營,都能透過新聞稿發布,提升曝光及知名度!",
- "wrap": true,
- "size": "13px",
- "align": "start",
- "offsetTop": "10px"
- }
- ]
- },
- "footer": {
- "type": "box",
- "layout": "vertical",
- "spacing": "sm",
- "contents": [
- {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "button",
- "style": "link",
- "height": "sm",
- "action": {
- "type": "uri",
- "label": "請來採訪我",
- "uri": "https://page.line.me/choozmo"
- },
- "color": "#FFFFFF"
- }
- ],
- "backgroundColor": "#e47e4d",
- "offsetTop": "-3px"
- },
- {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "button",
- "style": "link",
- "height": "sm",
- "action": {
- "type": "uri",
- "label": "了解更多",
- "uri": "https://page.line.me/choozmo"
- },
- "color": "#FFFFFF"
- }
- ],
- "backgroundColor": "#06C152"
- }
- ],
- "flex": 0
- }
- }
- """
- data2="""
- {
- "type": "bubble",
- "header": {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "text",
- "text": "集仕多 ChoozMo",
- "weight": "bold",
- "size": "xl",
- "color": "#ffffff"
- },
- {
- "type": "text",
- "text": "新聞 AI 主播媒體聯播網最佳方案",
- "size": "md",
- "color": "#ffffff"
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "xxl",
- "url": "https://ppt.cc/fLP10x@.png",
- "offsetTop": "xs"
- }
- ],
- "justifyContent": "flex-end",
- "offsetStart": "255px",
- "position": "absolute",
- "offsetBottom": "20px"
- }
- ],
- "backgroundColor": "#e1642b"
- },
- "hero": {
- "type": "image",
- "url": "https://ppt.cc/fDmzAx@.png",
- "size": "full",
- "aspectRatio": "20:13",
- "offsetTop": "lg"
- },
- "body": {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "text",
- "text": "圖文+影音+聯播",
- "color": "#aaaaaa",
- "size": "sm"
- },
- {
- "type": "text",
- "text": "全方位媒體曝光,一次到位!",
- "color": "#aaaaaa",
- "size": "sm"
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "md",
- "url": "https://ppt.cc/feXZPx@.png",
- "offsetTop": "xs"
- },
- {
- "type": "text",
- "text": "網路新聞圖文報導",
- "offsetStart": "md",
- "color": "#e47e4d",
- "weight": "bold"
- }
- ]
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "md",
- "url": "https://ppt.cc/feXZPx@.png",
- "offsetTop": "xs"
- },
- {
- "type": "text",
- "text": "十二家網路媒體聯播",
- "offsetStart": "md",
- "color": "#e47e4d",
- "weight": "bold"
- }
- ]
- },
- {
- "type": "box",
- "layout": "baseline",
- "margin": "md",
- "contents": [
- {
- "type": "icon",
- "size": "md",
- "url": "https://ppt.cc/feXZPx@.png",
- "offsetTop": "xs"
- },
- {
- "type": "text",
- "text": "AI 主播影音播報影片",
- "offsetStart": "md",
- "color": "#e47e4d",
- "weight": "bold"
- }
- ]
- },
- {
- "type": "box",
- "layout": "horizontal",
- "margin": "lg",
- "spacing": "sm",
- "contents": [
- {
- "type": "text",
- "text": "一次到位擁有,只要",
- "margin": "none",
- "size": "sm",
- "gravity": "center",
- "color": "#2384e3",
- "weight": "bold"
- },
- {
- "type": "text",
- "text": "$36,000",
- "size": "xxl",
- "offsetStart": "5px",
- "weight": "bold",
- "color": "#2384e3"
- }
- ],
- "backgroundColor": "#fff3ed",
- "background": {
- "type": "linearGradient",
- "angle": "0deg",
- "startColor": "#fff3ed",
- "endColor": "#ffffff"
- }
- },
- {
- "type": "text",
- "text": "不論是公司宣傳/產品發表/品牌經營,都能透過新聞稿發布,提升曝光及知名度!",
- "wrap": true,
- "size": "13px",
- "align": "start",
- "offsetTop": "10px"
- }
- ]
- },
- "footer": {
- "type": "box",
- "layout": "vertical",
- "spacing": "sm",
- "contents": [
- {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "button",
- "style": "link",
- "height": "sm",
- "action": {
- "type": "uri",
- "label": "請來採訪我",
- "uri": "https://page.line.me/choozmo"
- },
- "color": "#FFFFFF"
- }
- ],
- "backgroundColor": "#e47e4d",
- "offsetTop": "-3px"
- },
- {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "button",
- "style": "link",
- "height": "sm",
- "action": {
- "type": "uri",
- "label": "了解更多",
- "uri": "https://ai.choozmo.com/"
- },
- "color": "#FFFFFF"
- }
- ],
- "backgroundColor": "#06C152"
- },
- {
- "type": "box",
- "layout": "horizontal",
- "contents": [
- {
- "type": "image",
- "url": "https://ppt.cc/fHYTTx@.png",
- "offsetStart": "35px",
- "size": "xl",
- "position": "absolute"
- },
- {
- "type": "text",
- "text": "技術提供",
- "offsetBottom": "15px",
- "color": "#8B8B8B",
- "size": "sm",
- "weight": "bold",
- "offsetEnd": "40px",
- "position": "absolute"
- }
- ],
- "action": {
- "type": "uri",
- "label": "action",
- "uri": "https://page.line.me/choozmo"
- },
- "width": "100%",
- "height": "50px",
- "alignItems": "center",
- "offsetTop": "5px"
- }
- ],
- "flex": 0,
- "height": "160px"
- }
- }
- """
- bubble="""
- {
- "type": "bubble",
- "size": "micro",
- "hero": {
- "type": "image",
- "url": "https://scdn.line-apps.com/n/channel_devcenter/img/flexsnapshot/clip/clip10.jpg",
- "size": "full",
- "aspectMode": "cover",
- "aspectRatio": "320:213"
- },
- "body": {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "text",
- "text": "{{title }}",
- "weight": "bold",
- "size": "sm",
- "wrap": true
- },
- {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "box",
- "layout": "baseline",
- "spacing": "sm",
- "contents": [
- {
- "type": "text",
- "text": "ChoozMo商情AI",
- "wrap": true,
- "color": "#8c8c8c",
- "size": "xs",
- "flex": 5
- }
- ]
- }
- ]
- }]
- }
- }
- """
- bubble2="""
- {
- "type": "bubble",
- "header": {
- "type": "box",
- "layout": "horizontal",
- "position": "relative",
- "backgroundColor": "#FFFFFFFF",
- "contents": [
- {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "image",
- "url": "https://i.imgur.com/wQbJeGc.png",
- "margin": "none",
- "align": "end",
- "gravity": "top",
- "size": "md",
- "aspectRatio": "16:5",
- "action": {
- "type": "uri",
- "label": "ChoozMo",
- "uri": "https://cmm.ai/line"
- }
- },
- {
- "type": "text",
- "text": "今日熱搜",
- "weight": "bold",
- "color": "#BEB7B7FF",
- "position": "absolute",
- "offsetTop": "5px",
- "contents": []
- }
- ]
- }
- ]
- },
- "hero": {
- "type": "image",
- "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_4_news.png",
- "size": "full",
- "aspectRatio": "20:13",
- "aspectMode": "cover",
- "action": {
- "type": "uri",
- "label": "Action",
- "uri": "https://linecorp.com/"
- }
- },
- "body": {
- "type": "box",
- "layout": "horizontal",
- "spacing": "md",
- "contents": [
- {
- "type": "spacer"
- },
- {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "text",
- "text": "A1",
- "size": "xs",
- "flex": 1,
- "gravity": "top",
- "contents": []
- },
- {
- "type": "text",
- "text": "A2",
- "size": "xs",
- "flex": 2,
- "gravity": "center",
- "contents": []
- },
- {
- "type": "text",
- "text": "A3",
- "size": "xs",
- "flex": 2,
- "gravity": "center",
- "contents": []
- },
- {
- "type": "text",
- "text": "A4",
- "size": "xs",
- "flex": 1,
- "gravity": "bottom",
- "contents": []
- },
- {
- "type": "spacer"
- }
- ]
- }
- ]
- },
- "footer": {
- "type": "box",
- "layout": "horizontal",
- "contents": [
- {
- "type": "button",
- "action": {
- "type": "uri",
- "label": "More",
- "uri": "https://cmm.ai/line"
- }
- }
- ]
- }
- }
- """
- 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
- #from opengraph import OpenGraph
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/gtrends?charset=utf8mb4')
- cursor=db.query('SELECT distinct qtitle FROM gtrends.trending_search_flat order by dt desc limit 5')
- qtitles=[]
- for c in cursor:
- qtitles.append(c['qtitle'])
- result=[]
- for qt in qtitles:
- cursor=db.query('SELECT distinct trending_search_flat.qtitle,trending_search_flat.atitle,trending_search_flat.aimg,trending_search_flat.aurl,kw_related.original,kw_related.kw FROM gtrends.trending_search_flat,kw_related where trending_search_flat.qtitle=kw_related.original and trending_search_flat.qtitle="'+qt+'" order by trending_search_flat.dt desc')
- title=None
- imgurl=None
- imgtitle=qlink=None
- k1=k2=k3=k4=None
- lst_dict={}
- for c in cursor:
- title=c['qtitle']
- qlink=c['aurl']
- imgtitle=c['atitle']
- # imgurl=c['aimg']
- print(qlink)
- if imgurl is None:
- try:
- video = opengraph.OpenGraph(url=qlink)
- if video.is_valid():
- if video['image'] is not None:
- imgurl=video['image']
- print('GET OG IMAGE **************')
- print(imgurl)
- except:
- traceback.print_exc()
- imgurl=None
- lst_dict[c['kw']]=1
- if len(lst_dict)>=4:
- break
- if imgurl is None:
- print('none')
- imgurl=c['aimg']
- print(lst_dict)
- lst=list(lst_dict.keys())
- k1=lst[0]
- k2=lst[1]
- if len(lst)>=3:
- k3=lst[2]
- else:
- k3=' '
- if len(lst)>=4:
- k4=lst[3]
- else:
- k4=' '
- result.append({'title':title,'imgurl':imgurl,'qlink':qlink,'imgtitle':imgtitle,'K1':k1,'K2':k2,'K3':k3,'K4':k4})
- result_lst=result
- print(result)
- 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()
|