DAY 16 将含LINE emoji团购讯息与关键字存到资料库

再上篇中撷取到的讯息只会即时传到聊天室,并不会保存下来。要保存讯息的话,就要把讯息保存到资料库。

建立讯息资料表

这边设计资料表讯息与LINE emoji存放的资料表,message_emoji的mid为FK关联到group_buying_message的mid

group_buying_message

mid keyword message_text

message_emoji

eid mid index product_id emoji_id

https://ithelp.ithome.com.tw/upload/images/20210928/20140165eMqGRI6UBy.pnghttps://ithelp.ithome.com.tw/upload/images/20210928/201401655nzRks9Rc7.png
mid为FK关联到group_buying_message的mid
https://ithelp.ithome.com.tw/upload/images/20210928/20140165yhioQBqaYy.png

存放资料到资料表

def update_emoji_message(text,keyword,emojis):
    cursor = conn.cursor()
    cursor.execute("INSERT INTO group_buying_message (message_text, keyword) VALUES (%s, %s);", (text, keyword))
    cursor.execute(f"SELECT mid FROM group_buying_message WHERE message_text='{text}';")
    row = cursor.fetchone()
    for emoji in emojis:      
        cursor.execute("INSERT INTO message_emoji (mid, index, product_id, emoji_id) VALUES (%s, %s, %s, %s);", (row, emoji.index, emoji.product_id, emoji.emoji_id))
    conn.commit()
    cursor.close()
    print("successfully update emoji message")

https://ithelp.ithome.com.tw/upload/images/20210928/20140165XC2xCFhhE9.png
https://ithelp.ithome.com.tw/upload/images/20210928/2014016504qYM597VP.png
https://ithelp.ithome.com.tw/upload/images/20210928/20140165Q0GpTkdPQW.png


<<:  Unity与Photon的新手相遇旅途 | Day13-攻击优化

>>:  Stream Processing (1-1) - Transmitting Event Streams

变数 基础

简单介绍一下变数在JS中的几个性质,之後的篇章会比较深入的讲解,这些性质背後的原因们 看变数的值,决...

Day26 Let's ODOO: ODOO Studio

今天来介绍Odoo studio,对於程序苦手或非程序人员,运用Odoo studio可以直接透过见...

Vue Router实作

在昨天介绍了vue-router,我们知道vue-router就是扮演一个网址提供者的脚色,让每个画...

[Day 22]从零开始学习 JS 的连续-30 Days---阵列操作介绍 (下篇)

阵列操作介绍 (下篇) 介绍四种阵列运用: map filter find findlndex 3....

DAY29:开启API服务(完赛)

部署及开启API服务-flask 导入套件 import base64 import datetim...