-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
31 lines (28 loc) · 1.03 KB
/
test.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
import itchat
import psycopg2
#微信登陆
itchat.auto_login(hotReload=True)
# itchat.send('Hello,filehelper',toUserName='filehelper')
# postgresql数据库连接
conn = psycopg2.connect(dbname="mydb",user="dbuser",password="123qwe",host="172.27.199.132",port="5432")
print("Opened database successfuly!")
cur = conn.cursor()
friends = itchat.get_friends(update=True)
owner = friends[0]['NickName']
for friend in friends:
del friend['MemberList']
friend['Owner'] = owner
cols = ','.join(friend.keys())
qmarks = ','.join(list(['%s'] * len(friend)))
datas = tuple(friend.values())
sql = 'insert into wx_friend_list(Owner,{}) values{};'.format(cols,datas)
print(sql)
break
# cur.execute(sql)
# conn.commit()
# cur.execute('select NickName,Sex from wx_friend_list limit 2;')
# vals = cur.fetchall()
# data = [dict((cur.description[i][0], value) for i, value in enumerate(row)) for row in cur.fetchall()]
# print('Now The Table wx_friend_list have %d rows.' %(data[0]['count']))
# print(data['sex'])
conn.close