DAY 30完成团购机器人

前面的设置中文字体,发现不能在heroku上使用
这边我用matplotlib.font_manager 的 FontProperties直接使用指定路径的字体来代替

fontname='font/Arial Unicode MS.ttf'
for key, cell in tab.get_celld().items():
    row, col = key
    if row >= 0 and col >= 0:
        cell.set_text_props(fontproperties=FontProperties(fname=fontname))

修改後

if(event.message.text[:3:]=="团购" and rights[2]): #view right
    cursor = conn.cursor()
    cursor.execute(f"SELECT keyword,name,quantity FROM group_buying_user NATURAL JOIN group_buying_message order by keyword;")
    users = cursor.fetchall()
    cursor.close()
    fig, ax =plt.subplots(1,1)
    data=[]
    color=[]
    color_list = ["#89C6C6","#A889C6","#C68989","#A8C689","#C07BC0","#C6C689"]
    category=''
    i=0
    column_labels=['keyword','name','quantity']
    for user in users:
        if not category==user[0]:
            if i==len(color_list)-1:
                i=0
            else:
                i=i+1
        color.append([color_list[i],color_list[i],color_list[i]])
        category=user[0]
        data.append([user[0],user[1],user[2]])
    ax.axis('tight')
    ax.axis('off')
    tab=ax.table(cellText=data,colColours=["#DDDDDD"]*3,cellColours=color,colLabels=column_labels,cellLoc='center',loc="center")
    fontname='font/Arial Unicode MS.ttf'
    for key, cell in tab.get_celld().items():
        row, col = key
        if row >= 0 and col >= 0:
            cell.set_text_props(fontproperties=FontProperties(fname=fontname))
    plt.savefig('img/table.png',dpi=200)
    CLIENT_ID='ceda715b6015fcb'
    PATH = "img/table.png"
    im = pyimgur.Imgur(CLIENT_ID)
    uploaded_image = im.upload_image(PATH, title="iThome-2021")
    print(uploaded_image.link)
    message = ImageSendMessage(
        original_content_url=uploaded_image.link,
        preview_image_url=uploaded_image.link
    )
    line_bot_api.reply_message(event.reply_token,message)

推送至Heroku後功能测试

新增团购讯息

https://ithelp.ithome.com.tw/upload/images/20211012/20140165eW38tSfSdL.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140165ofgzveiOra.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140165pkggyfem6z.png

我要+1

https://ithelp.ithome.com.tw/upload/images/20211012/201401656sbWuZ6jxB.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140165vrEetF3i8K.png
更新数量
https://ithelp.ithome.com.tw/upload/images/20211012/20140165g7Z4wstFGx.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140165P4BlBsVE5T.png

手动新增团购者

https://ithelp.ithome.com.tw/upload/images/20211012/201401653JvCekF88K.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140165HLyUxZZ66e.png

手动删除团购者

https://ithelp.ithome.com.tw/upload/images/20211012/20140165yN9JYxX6yu.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140165adbsMz6jS3.png

查询团购讯息

https://ithelp.ithome.com.tw/upload/images/20211012/20140165nCeQ3eXilE.png

删除团购讯息

https://ithelp.ithome.com.tw/upload/images/20211012/201401651JqvM1ET5G.png
https://ithelp.ithome.com.tw/upload/images/20211012/20140165WcuebFcuYM.png


<<:  【Day 26】渲染备忘:Memo

>>:  ## [Day27] Video Speed Controller UI

[重构倒数第28天] - 关於拆分 Components 的学问

前言 该系列是为了让看过Vue官方文件或学过Vue但是却不知道怎麽下手去重构现在有的网站而去规画的系...

python 中 pickle 读档问题的解决方法

前言 要读取 .pkl 档,结果遇到各种状况,在网路上查了许多资料後终於解决了! 在这边简单做个过程...

Day16 开发套件 - 实作EventChannel

使用上跟MethodChannel类似,EventChannel即为MethodChannel与St...

EP 3: Use Shell to layout TopStore App

Hello, 各位 iT邦帮忙 的粉丝们大家好~~~ 本篇是 Re: 从零开始用 Xamarin 技...

[ Day 2 ] - 变数与型别(二)

变数与型别(二) 变数 简单回顾一下,变数的宣告方式 let catNum = 3; 用比较口语的方...