|
@@ -11,8 +11,8 @@ import json
|
|
|
app = fastapi.FastAPI()
|
|
|
|
|
|
# bot config
|
|
|
-line_bot_api = LineBotApi("SJT7VPT4RMQFLcS27jQBy3FcC24gtDrkcwJWZ5Xzqesr5T78LOKudHEJzt0k3b2S7n4KPwf27J7DVz2c8NQ4plSaaQylEeB1cYrfejaE/RPG/lCIQBYe4iBTzo26s4i2PcmT89837per/lTyvhVIKAdB04t89/1O/w1cDnyilFU=")
|
|
|
-handler = WebhookHandler("411ae3ef7e766739ed2c2c27b249d010")
|
|
|
+# line_bot_api = LineBotApi("SJT7VPT4RMQFLcS27jQBy3FcC24gtDrkcwJWZ5Xzqesr5T78LOKudHEJzt0k3b2S7n4KPwf27J7DVz2c8NQ4plSaaQylEeB1cYrfejaE/RPG/lCIQBYe4iBTzo26s4i2PcmT89837per/lTyvhVIKAdB04t89/1O/w1cDnyilFU=")
|
|
|
+# handler = WebhookHandler("411ae3ef7e766739ed2c2c27b249d010")
|
|
|
|
|
|
# db connect
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
@@ -26,11 +26,24 @@ async def callback(request: fastapi.Request):
|
|
|
handler.handle(body.decode('utf-8'), signature)
|
|
|
return 'OK'
|
|
|
|
|
|
+@app.get("/collection/{userid}")
|
|
|
+def collection(userid):
|
|
|
+ xname = userid
|
|
|
+ sql = 'SELECT * FROM nft WHERE userid="'+xname+'"'
|
|
|
+ result = db.query(sql)
|
|
|
+ rows={}
|
|
|
+ i = 0
|
|
|
+ for row in result:
|
|
|
+ rows[i]=row
|
|
|
+ i+=1
|
|
|
+ return json.dumps(rows)
|
|
|
+
|
|
|
# follow event
|
|
|
@handler.add(FollowEvent)
|
|
|
def handle_follow(event):
|
|
|
# get user id when follow
|
|
|
- rand_num = '_test_000_000_000'
|
|
|
+ real_user_id = event.source.user_id
|
|
|
+ rand_num = '_test_000_000_002'
|
|
|
user_id = event.source.user_id+rand_num
|
|
|
|
|
|
# create user account
|
|
@@ -44,9 +57,9 @@ def handle_follow(event):
|
|
|
user_account = dict_str['account']
|
|
|
user_address = user_account['address']
|
|
|
# write in sql
|
|
|
- data = dict(userid=user_id, useraddress=user_address)
|
|
|
+ data = dict(userid=real_user_id, useraddress=user_address)
|
|
|
table.insert(data)
|
|
|
- print(event.source.user_id)
|
|
|
+ print(" Follow event: "+event.source.user_id)
|
|
|
line_bot_api.reply_message(
|
|
|
event.reply_token,
|
|
|
TextSendMessage(text='歡迎加入好友'))
|
|
@@ -69,6 +82,8 @@ def message(event):
|
|
|
template=button_template_message))
|
|
|
|
|
|
elif '我要接收' in event.message.text:
|
|
|
+ user_id = event.source.user_id
|
|
|
+ print(" message event: "+user_id)
|
|
|
button_template_message = ButtonsTemplate(
|
|
|
title=' ',
|
|
|
text='點擊並打開接收頁面,即可分享接收地址給對方!',
|