-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspread_sheet.py
executable file
·117 lines (88 loc) · 3.06 KB
/
spread_sheet.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from datetime import datetime
from plyer import notification
import ezodf
import json
import os
def get_config():
script_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(script_dir, 'config.json')
with open(config_path, 'r') as file:
config = json.load(file)
return config
def verify_file_path(file_path):
if not os.path.exists(file_path):
show_notification(
'\u26D4 File path does not exist: check your config.json file!'
)
return False
return True
def get_current_date():
return datetime.now().strftime('%Y-%m-%d')
def convert_time_format(time_obj):
output_format = 'PT%HH%MM%SS,0000S'
return time_obj.strftime(output_format)
def strip_cell_value(cell_value):
return cell_value[2:7].replace('H', ':')
def show_notification(message):
notification.notify(
title='Time Tracking Tool',
message=message,
timeout=5,
)
def get_index(file_path, current_date):
doc = ezodf.opendoc(file_path)
sheet = doc.sheets[-1]
for index, row in enumerate(sheet.rows(), start=0):
if index == 0:
continue
date_in_column = row[0].value
if date_in_column is None:
break
if date_in_column == current_date:
return index
show_notification(
'\u26D4 No date index matched: check your spread sheet!'
)
return None
def write_start_time():
start_time = datetime.now()
current_date = get_current_date()
config = get_config()
file_path = config['file_path']
if verify_file_path(file_path) is True:
index = get_index(file_path, current_date)
doc = ezodf.opendoc(file_path)
sheet = doc.sheets[-1]
if start_time:
if sheet[index, 1].value == None:
show_notification(
f'\U0001F916 Clocking In: {start_time.strftime("%H:%M")}'
)
start_time_obj = convert_time_format(start_time)
sheet[index, 1].set_value(start_time_obj, 'time')
doc.save()
else:
show_notification(
f'\u26D4 Already Clocked In at: {strip_cell_value(sheet[index, 1].value)}'
)
def write_end_time():
end_time = datetime.now()
current_date = get_current_date()
config = get_config()
file_path = config['file_path']
if verify_file_path(file_path) is True:
index = get_index(file_path, current_date)
doc = ezodf.opendoc(file_path)
sheet = doc.sheets[-1]
if end_time:
if sheet[index, 2].value == None:
show_notification(
f'\U0001F916 Clocking Out: {end_time.strftime("%H:%M")}'
)
end_time_obj = convert_time_format(end_time)
sheet[index, 2].set_value(end_time_obj, 'time')
doc.save()
else:
show_notification(
f'\u26D4 Already Clocked Out at: {strip_cell_value(sheet[index, 2].value)}'
)