-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaveRedisData.py
54 lines (42 loc) · 1.45 KB
/
SaveRedisData.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
import redis
import csv
from datetime import date
import json
r = redis.StrictRedis(host='localhost', port=6379, db=0)
allData = []
for key in r.keys():
if key == b'StudentId_Username_CollectedData':
continue
data = json.loads(r.get(key))
allData.append(data)
# print(allData)
# print(allData)
# print()
today = date.today()
# dd/mm/YY
d1 = today.strftime("%d-%m-%Y")
with open('savedData/data'+str(d1)+".csv", mode='w', encoding='utf16') as dataFile:
dataFile = csv.writer(dataFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
dataFile.writerow(['userId', 'chatId', 'username', 'studentID' , 'fullName', 'WantsChild' , 'parentHood' , 'lang'])
for i in range(0, len(allData)):
dictionary = allData[i]
a = dictionary['userId']
b = dictionary['chatId']
c = dictionary['username']
d = '-none-'
e = '-none-'
f = '-none-'
g = '-none-'
h = '-none-'
if 'studentID' in dictionary:
d = dictionary['studentID']
if 'fullName' in dictionary:
e = dictionary['fullName']
if 'WantsChild' in dictionary:
f = dictionary['WantsChild']
if 'parentHood' in dictionary:
g = dictionary['parentHood']
if 'lang' in dictionary:
h = dictionary['lang']
print(a, b , c ,d , e , f, g, h)
dataFile.writerow( [a, b , c ,d , e , f, g, h] )