-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hbmp
executable file
·296 lines (242 loc) · 12.5 KB
/
hbmp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/python3
import main
import acc
import datetime as dt
import os
import json
import toml
import sys
from colors import color
os.chdir(os.path.dirname(os.path.realpath(__file__)))
try:
dic = json.load(open(os.getcwd()+'/stats.json'))
except:
dic = {}
try:
sett = toml.load(open(os.getcwd()+'/config.toml'))
except:
sett = {}
try:
acct = toml.load(open(os.getcwd()+'/.account.toml'))
except:
acct = {}
if sett == {}:
sett["defcol"] = "#FFFFFF"
sett["cols"] = []
defcol = sett["defcol"]
cols = sett["cols"]
if acct == {}:
acct["loggedin"] = False
sett["username"] = ""
loggedin = acct["loggedin"]
username = acct["username"]
comms = """
usage: hbmp [command] ([subcommand] [parameters] ([options]))
list of commands, parameters and options:
command:
-a, --arg. [parameter] ([option]) description
habit:
-a, --add [name] add a new habit (if not already existing).
-r, --remove [habit] remove a habit.
-t, --track [day] ([habit] [number]) add or edit a record.
-l, --list list all habits.
-m, --move [habit] [habit2] moves one habit after another habit.
-s, --steps [habit] [stepno] set the default number of steps in heatmap (number from 1-4)
map:
-d, --day [start] [end] ([colors]) view heatmap for all habits from one day to another.
-m, --month [start] [end] ([colors]) view heatmap for all habits from the start of a month to the beginning of another.
-y, --year [year] [habit] ([colors]) view yearly calendar heatmap for a habit.
-b, --bydur [start] [end] [duration] ([colors]) view heatmap based on average of week/month/year.
acc:
-i, --login log in to habitmap.
-o, --logout log out from habitmap.
-e, --edit [credential] [new] edit habitmap account credentials.
-d, --delete delete habitmap account.
help: see all commands and explanations.
samplecolors: ([colors]) see all custom colors or the given colors in the terminal.
"""
help = """
for more comprehensive and clear explanations, visit https://shuu-wasseo.github.io/habitmap-docs.
commands:
habit:
-a, --add [name]: add a new habit.
adds a new habit with name [name] to the database.
[name]: any string.
-r, --remove [name]: removes a habit.
removes the habit named [name] from the database.
[name]: any string.
-t, --track [day] ([habit] [number]): adds or edits a record.
adds or edits the record of habit [habit] on [day] and changes it to [stepno].
if [habit] and [number] are left blank, you will be prompted to enter a number for each habit.
[day]: either "tdy", "yst", the first three letters of a day of the week or a date in ISO format (YYYY-MM-DD).
[habit]: name of an existing habit.
[number]: a number from 0 to the default step number.
-l, --list: lists all habits.
-m, --move [habit1] [habit2]: moves one habit to right after another habit.
moves [habit1] from its origial position to right after [habit2].
[habit1], [habit2]: name of an existing habit.
-s, --steps [habit] [stepno]: sets the number of steps.
sets the default number of steps for [habit] to [stepno]
having one step would mean that you either have or have not done the habit but having more steps allows you to indicate anything in between.
[habit]: name of an existing habit.
[stepno]: any number from 1-4.
map:
-d, --day [start] [end] ([colors]): view day heatmap for all habits.
displays a single bar of each habit's data from [start] to [end] as well as the overall completion of each day's habits, optionally in [colors].
[start], [end]: either "tdy", "yst", the first three letters of a day of the week or a date, month or year in ISO format (YYYY-MM-DD).
[colors]: any number of hex codes (no preceding #).
-b, --bydur [start] [end] [duration] ([colors]): view heatmap for all habits based on week/month/yearly average.
displays a single bar of each habit's data from [start] to [end] based on average for every [duration], optionally in [colors].
[start], [end]: either "tdy", "yst", the first three letters of a day of the week or a date, month or year in ISO format (YYYY-MM-DD).
[duration]: either "week", "month" or "year"
[colors]: any number of hex codes (no preceding #).
-y, --year [year] [habit] ([colors]): view yearly calendar heatmap for a habit.
displays a calendar heatmap of the data in [habit] for [year], optionally in [colors].
[habit]: name of an existing habit.
[year]: any valid integer from 1 to 9999 (based on python's datetime module's limits)
[colors]: any number of hex codes (no preceding #).
acc:
-i, --login: log in to habitmap.
-o, --logout: log out from habitmap.
-e, --edit [credential] [new]: edit habitmap account credentials.
changes [credential] to [new].
[credential]: either "username" or "password"
[new]: the new username/password.
-d, --delete: delete habitmap account.
help: see this message.
samplecolors ([colors]): see colors displayed in the terminal.
if [colors] is entered, the colors listed will be printed out. otherwise, all custom color aliases in config.toml will be printed out.
[colors]: any number of hex codes (no preceding #).
explaining steps:
steps are the number of different values enterable for each record. if a habit only has the option to be marked as done or not done, we count that as one step.
if a habit has two steps, one would be allowed to mark the habit as done, undone or half-done. similar rules apply for three or four steps.
the step conversion table is as follows:
og max no. of steps: in 1-step: in 2-step: in 3-step in 4-step:
1 (0, 1) (0, 1) (0, 2) (0, 3) (0, 4)
2 (0, 1, 2) (0, 1, 1) (0, 1, 2) (0, 2, 3) (0, 2, 4)
3 (0, 1, 2, 3) (0, 0, 1, 1) (0, 1, 1, 2) (0, 1, 2, 3) (0, 1, 3, 4)
4 (0, 1, 2, 3, 4) (0, 0, 1, 1, 1) (0, 1, 1, 2, 2) (0, 1, 2, 2, 3) (0, 1, 2, 3, 4)
note that in printing heatmaps, all numbers will be converted to their 4-step equivalents.
"""
if len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] not in ["help", "samplecolors", "acc"]):
print(comms)
else:
match sys.argv[1]:
case "habit":
match sys.argv[2]:
case "-a" | "--add":
main.add(dic, sys.argv[3])
case "-r" | "--remove":
try:
try:
del dic[sys.argv[3]]
except:
print("not found")
else:
print(f" habit {sys.argv[3]} removed.")
except:
print("not enough arguments.")
case "-t" | "--track":
if len(sys.argv) == 4:
main.multitrack(dic, main.cday(sys.argv[3]))
elif len(sys.argv) == 6:
main.track(dic, *sys.argv[3:6])
else:
print("not enough arguments.")
case "-l" | "--list":
print(" you have the following habits:")
for habit in dic:
print(" - " + habit)
case "-m" | "--move":
if len(sys.argv) == 5:
dic = main.rearr(dic, sys.argv[3], sys.argv[4])
print(" you have the following commands:")
for habit in dic:
print(" - " + habit)
else:
print("not enough arguments.")
case "-s" | "--steps":
if len(sys.argv) == 5:
try:
new = int(sys.argv[4])
if new < 1 or new > 4:
raise TypeError
except:
print("invalid number.")
else:
if sys.argv[3] in dic:
dic[sys.argv[3]]["stepno"] = new
print(f" stepno for {sys.argv[3]} changed to {new}.")
else:
print("invalid habit.")
else:
print("not enough arguments.")
case _:
print("invalid command.")
case "map":
match sys.argv[2]:
case "-d" | "--day":
match len(sys.argv):
case 5:
main.daymap(*sys.argv[3:5], main.ccol(cols, defcol), dic, "day")
case _:
if len(sys.argv) >= 6:
main.daymap(*sys.argv[3:5], main.ccol(cols, sys.argv[5:]), dic, "day")
else:
print("not enough arguments.")
case "-y" | "--year":
match len(sys.argv):
case 5:
main.yearmap(*sys.argv[3:5], main.ccol(cols, defcol), dic)
case _:
if len(sys.argv) >= 6:
main.yearmap(*sys.argv[3:5], main.ccol(cols, sys.argv[5:]), dic)
else:
print("not enough arguments.")
case "-b" | "--bydur":
match len(sys.argv):
case 6:
main.daymap(*sys.argv[3:5], main.ccol(cols, defcol), dic, sys.argv[5])
case _:
if len(sys.argv) >= 7:
main.daymap(*sys.argv[3:5], main.ccol(cols, sys.argv[6]), dic, sys.argv[5])
else:
print("not enough arguments.")
case _:
print("invalid command.")
case "acc":
if len(sys.argv) <= 2:
if loggedin:
print(f"you are logged in as {username}.")
else:
print("you are not logged in.")
else:
match sys.argv[2]:
case "-i" | "login":
dic = acc.login(acct, dic, sett)
case "-o" | "logout":
acc.logout(acct, dic, sett)
case "-e" | "edit":
if len(sys.argv) < 5:
print("not enough arguments.")
else:
acc.editacct(acct, *sys.argv[3:])
case "-d" | "delete":
acc.removeacct(acct, dic, sett)
case "help":
print(help)
case "samplecolors":
if len(sys.argv) > 2:
string = ""
for x in main.ccol(cols, sys.argv[2:]):
string += color(f" ██ {x}", main.ccol(cols, [x])[0]) + "\n"
print(string)
else:
string = ""
for x in cols:
string += color(f" ██ {x[0]} ({x[1]})", main.ccol(cols, [x[1]])[0]) + "\n"
print(string)
case _:
print("invalid command.")
td = dt.date.today()
open(os.getcwd()+"/stats.json", "w").write(json.dumps(dic, indent=4))