-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavedata.py
58 lines (49 loc) · 1.26 KB
/
savedata.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
import pymysql
import csv
def get_category_info():
connect = pymysql.connect(
host="XXXX.XXXX.XXXX.XXXX",
port=3306,
user='root',
password='XXXX',
db='zhihu',
charset='utf8mb4'
)
cursor = connect.cursor()
sql = 'select * from category'
cursor.execute(sql)
category = cursor.fetchall()
connect.close()
return category
def get_club_info():
connect = pymysql.connect(
host="XXXX.XXXX.XXXX.XXXX",
port=3306,
user='root',
password='XXXX',
db='zhihu',
charset='utf8mb4'
)
cursor = connect.cursor()
sql = 'select * from club'
cursor.execute(sql)
club = cursor.fetchall()
connect.close()
return club
def category_to_csv():
data=get_category_info()
filename='data/category.csv'
with open(filename,'x',encoding='utf8') as f:
write=csv.writer(f,dialect='excel')
for item in data:
write.writerow(item)
def club_to_csv():
data=get_club_info()
filename='data/club.csv'
with open(filename,'x',encoding='utf8') as f:
write=csv.writer(f,dialect='excel')
for item in data:
write.writerow(item)
if __name__=='__main__':
category_to_csv()
club_to_csv()