【发布时间】:2019-04-03 12:58:14
【问题描述】:
我使用 Python 程序作为 webhook 创建了一个带有对话流的信使聊天机器人。在一个用例中:用户通过给出周数(1 周/2 周等)来请求每周报告。 Python 程序不需要数周作为参数,并将结果作为 csv 保存在我的本地。我想将该 csv 作为聊天机器人的附件发送给用户。
到目前为止,我将 csv 文件保存在与谷歌驱动器同步的本地驱动器中,并将链接发送给用户。每次用户想要不同周的销售文件更新时。但是在现实生活场景中,当多个用户同时要求报告时,其中一个用户得到了错误的文件(无论最新运行的查询)。
inte = get_parameter_from_req(req)
week_num = round(inte)
print(week_num)
#cusid = pd.DataFrame([inte],columns = ['Weeks'])
#cusid.to_csv('C:/Users/Jon/Desktop/Reporting BOT/Reporting Bot Code/num_of_weeks.csv',index = False)
print("Inside DB Test")
mydb = mysql.connector.connect(host="localhost",user="root",passwd="****",database = "jon_bp")
mycursor = mydb.cursor()
mycursor.execute("select * from trans where t_date between curdate()-interval %s week AND curdate()",(week_num,))
result = mycursor.fetchall()
dataf = pd.DataFrame(result)
dataf.columns = ['Name','Amount','t_date']
dataf.to_csv('C:/Users/jon/Desktop/Reporting BOT/Report on cloud/Weekly Report by Bot.csv',index = False)
response = {
'fulfillmentText': 'Hi! Sales report for {0} weeks is ready.'.format(str(week_num)) +"\n"+ 'You can download the report from here: fix url for report',
}
【问题讨论】:
标签: python mysql cloud dialogflow-es facebook-chatbot