-
Notifications
You must be signed in to change notification settings - Fork 1
/
convo_logs.py
107 lines (94 loc) · 3.39 KB
/
convo_logs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# MySQL Database Variables-----
# database = 'chatbotdb'
# feedback_table = 'feedback_logs'
# convo_table = 'convo_logs'
debug_mode = False
#------------------------------
# import mysql.connector
import json
import smtplib
from datetime import datetime
from datetime import timedelta
from settings import MAIL_USER_ID, MAIL_USER_PWD
# from settings import SQL_DB, SQL_HOST, SQL_PORT, SQL_PWD, SQL_USER
#----potential feedback system logs----------------------------------------------------------------------------
# def storeNewFeedbackLog(_log):
# mydb = mysql.connector.connect(
# user=SQL_USER,
# password=SQL_PWD,
# host=SQL_HOST,
# port=SQL_PORT,
# database=SQL_DB
# )
# mycursor = mydb.cursor(buffered=True)
# log = json.loads(_log)
# log = json.loads(log)
# timestamp = str(log['timestamp'])
# feedback = log['feedback']
# pred_senti = log['pred_senti']
# query_insert = 'INSERT INTO {db}.{table}'.format(db=database, table=feedback_table)
# query_insert = query_insert + ' VALUE ("{time}", "{fdbk}", {pred});'.format(time=timestamp, fdbk=feedback, pred=pred_senti)
# try:
# mycursor.execute(query_insert)
# mycursor.execute('SELECT * FROM {db}.{table};'.format(db=database, table=feedback_table))
# if debug_mode:
# print('Ran SQL')
# for x in mycursor:
# print(x)
# mydb.commit()
# mydb.close()
# return True
# except:
# return False
# def storeNewChat(_log):
# mydb = mysql.connector.connect(
# user=SQL_USER,
# password=SQL_PWD,
# host=SQL_HOST,
# port=SQL_PORT,
# database=SQL_DB
# )
# mycursor = mydb.cursor(buffered=True)
# log = json.loads(_log)
# log = json.loads(log)
# timestamp = datetime.now() + timedelta(hours=5)
# timestamp = timestamp + timedelta(minutes=30)
# dialogue = (json.dumps(log['dialogue'])).replace('"', '')
# query_insert = 'INSERT INTO {db}.{table} (time_stamp, convo)'.format(db=database, table=convo_table)
# query_insert = query_insert + 'VALUES ("{time}", "{dia}");'.format(time=timestamp, dia=dialogue)
# try:
# mycursor.execute(query_insert)
# mycursor.execute('SELECT * FROM {db}.{table};'.format(db=database, table=convo_table))
# if debug_mode:
# print('Ran SQL')
# for x in mycursor:
# print(x)
# mydb.commit()
# mydb.close()
# return True
# except:
# return False
def storeNewChat (_log):
try:
log = json.loads(_log)
log = json.loads(log)
timestamp = datetime.now() + timedelta(hours=5)
timestamp = timestamp + timedelta(minutes=30)
dialogue = (json.dumps(log['dialogue'])).replace('"', '')
TO = '[email protected]'
SUBJECT = "Feedback " + str(timestamp)
server = smtplib.SMTP('smtp.zoho.in', 587)
server.ehlo()
server.starttls()
server.login(MAIL_USER_ID, MAIL_USER_PWD)
TEXT = str(timestamp) + " | " + dialogue
BODY = '\r\n'.join(['To: %s' % TO,
'From: %s' % MAIL_USER_ID,
'Subject: %s' % SUBJECT,
'', TEXT])
server.sendmail(MAIL_USER_ID, [TO], BODY)
print ('chat mailed')
return True
except:
print ('error mailing chat')
return False