-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_album_infor.py
89 lines (79 loc) · 2.34 KB
/
get_album_infor.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
# -*- coding: utf8 -*-
import pymysql
import json
connection = pymysql.connect(host="切换为自己的数据库host",
user="root",
password="切换为自己的数据库密码",
port=int(62580),
db="mini_album",
charset='utf8',
cursorclass=pymysql.cursors.DictCursor,
autocommit=1)
def getUserInfor(connection, wecaht):
try:
connection.ping(reconnect=True)
cursor = connection.cursor()
search_stmt = (
"SELECT * FROM `users` WHERE `wechat`=%s"
)
data = (wecaht)
cursor.execute(search_stmt, data)
cursor.close()
result = cursor.fetchall()
if len(result) == 1:
result = result[0]
print(result)
return result['uid']
else:
return False
except Exception as e:
print("getUserInfor", e)
try:
cursor.close()
except:
pass
return False
def getAlbumInfor(connection, user, album):
try:
connection.ping(reconnect=True)
cursor = connection.cursor()
search_stmt = (
"SELECT * FROM `category` WHERE `user` = %s AND `cid` = %s"
)
data = (user, album)
cursor.execute(search_stmt, data)
cursor.close()
result = cursor.fetchall()
if len(result) == 1:
return {
"name": result[0]["name"],
"creattime": str(result[0]["publish"]),
"creatarea": result[0]["area"],
"remark": result[0]["remark"],
"cid": result[0]["cid"],
}
else:
return False
except Exception as e:
print(e)
try:
cursor.close()
except:
pass
return False
def main_handler(event, context):
try:
print(event)
body = json.loads(event['body'])
wecaht = body['wechat']
cid = body['cid']
user = getUserInfor(connection, wecaht)
result = getAlbumInfor(connection, user, cid)
except Exception as e:
print(e)
result = []
try:
connection.close()
except:
pass
return result