forked from 2series/smart-banking-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lennox_brain.py
executable file
·41 lines (40 loc) · 1.42 KB
/
lennox_brain.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
#!/usr/bin/python
import pymysql
import cgi, cgitb
import sys
import os
import config
import customer_details
def add_chat(from_id,to_id,text):
conn,cursor=config.connect_to_database()
sql="insert into chats(from_id,to_id,text) values('%s','%s','%s')"%(from_id,to_id,text)
try:
cursor.execute(sql)
conn.commit()
return "11"
except:
conn.rollback()
return "0"
def reload_chats(user_id,email_id):
conn,cursor=config.connect_to_database()
sql="select * from chats where from_id='%s' or to_id='%s' ORDER BY created_time ASC"%(user_id,user_id)
reload_mess=""
try:
cursor.execute(sql)
results=cursor.fetchall()
for row in results:
chat_id="chat_%s"%row[0]
from_id=row[1]
to_id=row[2]
text=row[3]
datetime=row[4]
time=datetime.strftime('%H : %M')
name=customer_details.get_any_value(email_id,"username")
profile_pic=customer_details.get_any_document(name,"profile_pic")
if int(to_id)!=0 or from_id==0:
reload_mess+="""<li id='%s' class="mess"><div><img src="images/jon-cart.jpg" alt="You" style="width:100%%;"><p class="text-left">%s</p><br/><span class="time-right">%s</span></div></li><br/>"""%(chat_id,text,time)
else:
reload_mess+="""<li id='%s' class='mess'><div><img src="%s" alt="Jon" class="right" style="height:50px;"><p class="text-right">%s</p><br/><span class="time-left">%s</span></div></li><br/>"""%(chat_id,profile_pic,text,time)
return reload_mess
except:
return "error"