-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.py
More file actions
75 lines (58 loc) · 1.6 KB
/
Copy pathhelp.py
File metadata and controls
75 lines (58 loc) · 1.6 KB
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
import json
import random
def p(text, *args):
''' easy print '''
print(text, *args, sep=' / ', end='\n')
def pcolor(text_code, color_num = 2):
''' color print '''
print(f'\033[3{color_num}m{text_code}\033[0m', end='\n')
def log_add(text, type = 'log'):
''' add login files '''
with open(f'./json/{type}.txt', "a", encoding='utf8') as f:
f.write(f'{text}\n')
def wtf(html, pg):
with open(f'./html/html{pg}.txt', "w", encoding='utf8') as f:
f.write(html)
def lf(filename):
with open(filename, 'r') as f:
return f.read()
def write_json(data, path):
with open(path, 'w', encoding='utf8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
def load_json(path):
with open(path, 'r', encoding='utf-8') as f:
return json.load(f)
def get_description_index(unit_code):
''' return index '''
unit = unit_code.replace('.', '')
nids = {
'ед':0,
'гр':1,
'кг':2,
'мл':3,
'л':4, 'литра':4,
'см':5,
'м':6,
'мин':7,
'ч':8,
'шт':9, 'штук':9,
'порц':10,
}
return (str(nids[unit]) if unit in nids.keys() else '')
def get_id():
return random.randrange(1992, 3999)
def get_maximun_m(t):
if t == 'radio':
return str(1)
if t == 'checkbox':
return str(10)
def get_type_m(t):
if t == 'radio':
return 'one_one'
if t == 'checkbox':
return 'all_one'
def get_list_gid(m_groups):
g_arr = []
for g_ in m_groups:
g_arr.append(g_['gid'])
return set(g_arr)