-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutillities.py
61 lines (46 loc) · 1.54 KB
/
utillities.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
59
60
61
import csv
import datetime
import re
def csv_reader(file, index=0):
with open(file, 'r', encoding="utf8") as f:
f_read = csv.reader(f)
next(f_read)
for line in f_read:
yield line[index]
def parser(data):
for i, j in data.items():
if type(j) is list and j[1] == '' or type(j) is int:
yield i
else:
yield f'{i}:{j[1]}'
def ep_group(source_dict, target_list):
# add ret statement
copy_list = target_list.copy()
for i in parser(source_dict):
for k in copy_list:
if i in k:
target_list.remove(k)
source_dict[i] += 1
def convert_time(time_input):
time_input = time_input.replace('min', 'm').strip().replace(' ', '')
if time_input == "--": # or '' - prob not working
return None
elif time_input.endswith('s'):
time_input = time_input[:time_input.find('m')+1]
if time_input == '':
return None
if re.search(r'[a-zA-Z]', str(time_input)) is None:
return str(datetime.timedelta(seconds=int(time_input))).split(':00')[0]
if len(time_input) >= 4 <= 5: # change
pattern = "%Hh%Mm"
elif time_input.endswith('m'):
pattern = "%Mm"
else:
pattern = "%Hh"
formatted = datetime.datetime.strptime(time_input, pattern).time()
return round(datetime.timedelta(hours=formatted.hour, minutes=formatted.minute).seconds / 3600, 2)
# show_1 = convert_time("3480")
# print(show_1)
# print(type(show_1))
# show_2 = convert_time("58min")
# print(show_2)