[DAY27]将Line讯息存入资料库(01)

再来就是我们要利用Line来记录我们的资料了,以下程序码我放在一个新增程序档

import psycopg2,os
from linebot.models import *

#回报记录情况
line_bot_api = '我们的lineAPI'
def insert_record(event):
    #确认字首开启以下程序
    if '学生纪录' in event.message.text:
        try:
            record_list = prepare_record(event.message.text)
			#利用log观察prepare_record是否正常运行
            print('prepare_record end')
            reply = line_insert_record(record_list)
			#观察我明天会讲到的纪录主程序line_insert_record是否正常运行
            print('line_insert_record end')
            remessages=TextSendMessage(text=reply)
        except:
            remessages=TextSendMessage(text='汇入失败了')
	#回报值给app.py
    return remessages
#准备资料
def prepare_record(text):
	#将我们所传的讯息分成一笔笔资料
    text_list = text.split('\n')
	#先宣告list
    record_list=[]
	#将一笔笔资料分别填入资料该属於的栏位
    for i in text_list[1(跳过学生记录这一行):](字串数量):
		#以空白键做分割记号
        temp_list = i.split(' ')
        temp_id = temp_list[0]
        temp_name = temp_list[1]
        temp_gender = temp_list[2]
        temp_grade = temp_list[3]
        prerecord=(temp_id,temp_name,temp_gender,temp_grade)
#将以上prerecord纪录的东西放入record_list的尾巴
        record_list.append(prerecord)
#回传给insert_record
    return record_list

<<:  Day 27 - WooCommerce: 建立虚拟帐号付款订单

>>:  Station list screen testing

D3JsDay15 了解WEB地图学,先懂一点地理学—web地图的科学

GIS地理资讯系统(Geographic Information System) 地理资讯系统这个名...

Day22. Blue Prism拯救贫穷大作战第三弹 -BP自动执行应用程序

还记得这次的铁人赛期间提到拯救贫穷大作战的前二弹, 今天来谈谈第三弹吧! 前一阵子连络上以前大学时期...

Day 11. slate × Interfaces × Document-Model

接下来的篇章我们会把目光聚焦於 interfaces/ 这个目录底下的内容,想确认 slate p...

见习村29 - Sum of Intervals

29 - Sum of Intervals Don't say so much, just codi...

[Day06] swift & kotlin 入门篇!(4) 基础语法-转型与合并使用

转型与连结 在JS中, 所有的转型与连结都是无感的 也因为太方便太无感 常常会跑出意外的结果 例如 ...