-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_handler.py
55 lines (43 loc) · 1.57 KB
/
data_handler.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
import json
from os import write
path = 'tg_bots/ig_ninja/data.json'
def user_id_str(jsonStr):
str_id = ''
for i in range(2, len(jsonStr)):
str_id += jsonStr[i]
if(jsonStr[i+2] == ':'):
return str_id
def Base(id, lang, name, sur, nick):
with open(path, 'r', encoding= 'utf-8') as file:
data = json.load(file)
with open(path, 'w', encoding='utf-8') as file:
if id_copy(data, id):
for i in data['People']:
if i['id'] == id:
i['language'] = lang
break
else:
data['People'].append({"id": id,"language": lang, "first_name": name, "last_name": sur, "nickname": nick})
data = json.dump(data, file, sort_keys= False, indent = 4, ensure_ascii = False)
def Stats(option_name):
with open(path, 'r', encoding= 'utf-8') as file:
data = json.load(file)
with open(path, 'w', encoding='utf-8') as file:
for i in data['Statistics']:
if option_name == "story":
i['story'] += 1
break
elif option_name == "profile_pic":
i['profile_pic'] += 1
break
elif option_name == "post":
i['post'] += 1
break
data = json.dump(data, file, sort_keys= False, indent = 4, ensure_ascii = False)
def id_copy(data, id):
list = []
for i in data["People"]:
list.append(i["id"])
if id in list:
return True
else: return False