forked from KoRaghav/askq-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
83 lines (73 loc) · 2.48 KB
/
user.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
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
def requestConnection():
mydb = MySQLdb.connect(
host='containers-us-west-162.railway.app',
user='root',
passwd='ufo2OWVGXtpgiPsXHUcW',
db='askq',
port=6118
)
return mydb
def requestCursor(conn):
return conn.cursor()
def dis_user(id):
conn = requestConnection()
cursor = requestCursor(conn)
cursor.execute('SELECT Creation_Date from User where ID = ' + str(id))
date = cursor.fetchone()
# cursor.execute('SELECT website_url from User where ID = ' + str(id))
# websiteurl = cursor.fetchone()
# cursor.execute('SELECT profile_image_url from User where ID = ' + str(id))
# profile = cursor.fetchone()
# cursor.execute('SELECT About_me from User where ID = ' + str(id))
# about=cursor.fetchone()
detail=cursor.execute('SELECT * from User where ID = ' + str(id))
detail=cursor.fetchone()
if date:
date = date[0]
d = date.day
mth = date.month
ye = date.year
date = str(d) + "/" + str(mth) + "/"+ str(ye)
else:
date=""
cursor.close()
conn.close()
return (date,detail)
def editDisplayname(id,name):
conn = requestConnection()
cursor = requestCursor(conn)
p=cursor.execute('Update User set Display_Name='+str(name)+' where Id= '+str('id'))
conn.commit()
cursor.close()
conn.close()
return "Done"
def editAboutme(id,name):
conn = requestConnection()
cursor = requestCursor(conn)
p=cursor.execute('Update User set About_me="'+str(name)+'" where Id= '+str(id))
conn.commit()
cursor.close()
conn.close()
return "Done"
def list_of_user_date(page,date,upvote,downvote,reputation):
conn = requestConnection()
cursor = requestCursor(conn)
offset=(page-1)*30
if date:
p=cursor.execute('select * from User order by Creation_Date limit 30 offset '+str(offset))
p=cursor.fetchall()
elif upvote:
p=cursor.execute('select * from User order by up_votes limit 30 offset '+str(offset))
p=cursor.fetchall()
elif downvote:
p=cursor.execute('select * from User order by down_votes limit 30 offset '+str(offset))
p=cursor.fetchall()
else:
p=cursor.execute('select * from User order by reputation limit 30 offset '+str(offset))
p=cursor.fetchall()
cursor.close()
conn.close()
return list(p)