papi-projects 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {papi_projects-0.2.3 → papi_projects-0.2.4}/PKG-INFO +1 -1
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/wrappers.py +16 -11
- {papi_projects-0.2.3 → papi_projects-0.2.4}/pyproject.toml +1 -1
- papi_projects-0.2.4/scripts/collate_toggl_hours.py +72 -0
- papi_projects-0.2.3/scripts/collate_toggl_hours.py +0 -66
- {papi_projects-0.2.3 → papi_projects-0.2.4}/README.md +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/__init__.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/mocks.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/project.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/tests/__init__.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/tests/test_project.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/tests/test_user.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/tests/test_userdb.json +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/tests/test_wrappers.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/papi/user.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/scripts/__init__.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/scripts/create_notion_project.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/scripts/create_project.py +0 -0
- {papi_projects-0.2.3 → papi_projects-0.2.4}/scripts/create_toggl_project.py +0 -0
|
@@ -436,7 +436,8 @@ class TogglTrackWrapper(Protocol):
|
|
|
436
436
|
self, start_time=None, end_time=pendulum.now().to_rfc3339_string()
|
|
437
437
|
) -> dict:
|
|
438
438
|
"""Gets all of the Toggl Track user's tracked hours for a given
|
|
439
|
-
time period. If no end_time is given, then the current time is used.
|
|
439
|
+
time period. If no end_time is given, then the current time is used.
|
|
440
|
+
Only works with start dates up to a maximum of three months ago.
|
|
440
441
|
|
|
441
442
|
:return: A dictionary containing the Toggl Track projects and hours tracked.
|
|
442
443
|
:rtype: dict
|
|
@@ -449,16 +450,20 @@ class TogglTrackWrapper(Protocol):
|
|
|
449
450
|
params={"start_date": start_time, "end_date": end_time},
|
|
450
451
|
)
|
|
451
452
|
times_json = r.json()
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
453
|
+
if isinstance(times_json, list):
|
|
454
|
+
times = {}
|
|
455
|
+
for t in times_json:
|
|
456
|
+
pid = t["pid"]
|
|
457
|
+
seconds = t["duration"]
|
|
458
|
+
hours = seconds / 60 / 60
|
|
459
|
+
if pid not in times:
|
|
460
|
+
times[pid] = hours
|
|
461
|
+
else:
|
|
462
|
+
times[pid] += hours
|
|
463
|
+
return times
|
|
464
|
+
else:
|
|
465
|
+
warnings.warn(times_json)
|
|
466
|
+
return None
|
|
462
467
|
else:
|
|
463
468
|
warnings.warn("Please provide a valid start date/time in RFC3339 format!")
|
|
464
469
|
return None
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import pendulum
|
|
3
|
+
import warnings
|
|
4
|
+
from papi.wrappers import TogglTrackWrapper
|
|
5
|
+
from papi import config
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
"""Main function of collate-toggl-hours script"""
|
|
9
|
+
|
|
10
|
+
# Set up argparse
|
|
11
|
+
parser = argparse.ArgumentParser()
|
|
12
|
+
parser.add_argument(
|
|
13
|
+
"-s", "--start", type=str, help="start date in YYYY-MM-DD format", required=True
|
|
14
|
+
)
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"-e", "--end", type=str, help="end date in YYYY-MM-DD format, if none supplied then end date is now", default=False
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"-o",
|
|
20
|
+
"--output",
|
|
21
|
+
type=str,
|
|
22
|
+
help="output TSV filename, omit to write to stdout",
|
|
23
|
+
default=False,
|
|
24
|
+
)
|
|
25
|
+
args = parser.parse_args()
|
|
26
|
+
|
|
27
|
+
# Set up start/end date
|
|
28
|
+
start_date = args.start
|
|
29
|
+
start_time = pendulum.parse(start_date).to_rfc3339_string()
|
|
30
|
+
end_date = args.end
|
|
31
|
+
if not end_date:
|
|
32
|
+
end_time = pendulum.now().to_rfc3339_string()
|
|
33
|
+
else:
|
|
34
|
+
end_time = pendulum.parse(end_date).to_rfc3339_string()
|
|
35
|
+
|
|
36
|
+
# Check that start time is not more than 3 months ago
|
|
37
|
+
if pendulum.now() < pendulum.parse(start_date).add(months=3):
|
|
38
|
+
# Set up Toggl Track API wrapper
|
|
39
|
+
#
|
|
40
|
+
# NOTE: you must have added Toggl Track API key and password, with
|
|
41
|
+
# variable names below to .env file in this directory
|
|
42
|
+
toggl_api_key = config["TOGGL_TRACK_API_KEY"]
|
|
43
|
+
toggl_api_password = config["TOGGL_TRACK_PASSWORD"]
|
|
44
|
+
toggl = TogglTrackWrapper(toggl_api_key, toggl_api_password)
|
|
45
|
+
|
|
46
|
+
# Tell wrapper which workspace to set as default
|
|
47
|
+
toggl_workspace = config["TOGGL_TRACK_WORKSPACE"]
|
|
48
|
+
toggl.set_default_workspace(toggl_workspace)
|
|
49
|
+
toggl.set_me()
|
|
50
|
+
|
|
51
|
+
# Get tracked hours and tracked project IDs/names
|
|
52
|
+
|
|
53
|
+
tracked_hours = toggl.get_user_hours(start_time=start_time, end_time=end_time)
|
|
54
|
+
projects = {p["id"]: p["name"] for p in toggl.get_user_projects() if p["id"] in tracked_hours}
|
|
55
|
+
hours_per_project = [(projects[t], tracked_hours[t]) for t in tracked_hours]
|
|
56
|
+
|
|
57
|
+
output = args.output
|
|
58
|
+
|
|
59
|
+
if output:
|
|
60
|
+
# If output filename provided, write to file
|
|
61
|
+
with open(output, "w") as out:
|
|
62
|
+
for h in sorted(hours_per_project, key=lambda x:x[1], reverse=True):
|
|
63
|
+
out.write(f"{h[0]}\t{h[1]}\n")
|
|
64
|
+
else:
|
|
65
|
+
# Otherwise, print out project names and tracked hours to stdout
|
|
66
|
+
for h in sorted(hours_per_project, key=lambda x:x[1], reverse=True):
|
|
67
|
+
print(f"{h[0]}\t{h[1]}")
|
|
68
|
+
else:
|
|
69
|
+
warnings.warn("Start time must not be more than 3 months ago!")
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
main()
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
import pendulum
|
|
3
|
-
from papi.wrappers import TogglTrackWrapper
|
|
4
|
-
from papi import config
|
|
5
|
-
|
|
6
|
-
def main():
|
|
7
|
-
"""Main function of collate-toggl-hours script"""
|
|
8
|
-
|
|
9
|
-
# Set up argparse
|
|
10
|
-
parser = argparse.ArgumentParser()
|
|
11
|
-
parser.add_argument(
|
|
12
|
-
"-s", "--start", type=str, help="start date in YYYY-MM-DD format", required=True
|
|
13
|
-
)
|
|
14
|
-
parser.add_argument(
|
|
15
|
-
"-e", "--end", type=str, help="end date in YYYY-MM-DD format, if none supplied then end date is now", default=False
|
|
16
|
-
)
|
|
17
|
-
parser.add_argument(
|
|
18
|
-
"-o",
|
|
19
|
-
"--output",
|
|
20
|
-
type=str,
|
|
21
|
-
help="output TSV filename, omit to write to stdout",
|
|
22
|
-
default=False,
|
|
23
|
-
)
|
|
24
|
-
args = parser.parse_args()
|
|
25
|
-
|
|
26
|
-
# Set up start/end date
|
|
27
|
-
start_date = args.start
|
|
28
|
-
start_time = pendulum.parse(start_date).to_rfc3339_string()
|
|
29
|
-
end_date = args.end
|
|
30
|
-
if not end_date:
|
|
31
|
-
end_time = pendulum.now().to_rfc3339_string()
|
|
32
|
-
else:
|
|
33
|
-
end_time = pendulum.parse(end_date).to_rfc3339_string()
|
|
34
|
-
|
|
35
|
-
# Set up Toggl Track API wrapper
|
|
36
|
-
#
|
|
37
|
-
# NOTE: you must have added Toggl Track API key and password, with
|
|
38
|
-
# variable names below to .env file in this directory
|
|
39
|
-
toggl_api_key = config["TOGGL_TRACK_API_KEY"]
|
|
40
|
-
toggl_api_password = config["TOGGL_TRACK_PASSWORD"]
|
|
41
|
-
toggl = TogglTrackWrapper(toggl_api_key, toggl_api_password)
|
|
42
|
-
|
|
43
|
-
# Tell wrapper which workspace to set as default
|
|
44
|
-
toggl_workspace = config["TOGGL_TRACK_WORKSPACE"]
|
|
45
|
-
toggl.set_default_workspace(toggl_workspace)
|
|
46
|
-
toggl.set_me()
|
|
47
|
-
|
|
48
|
-
# Get tracked hours and tracked project IDs/names
|
|
49
|
-
tracked_hours = toggl.get_user_hours(start_time=start_time, end_time=end_time)
|
|
50
|
-
projects = {p["id"]: p["name"] for p in toggl.get_user_projects() if p["id"] in tracked_hours}
|
|
51
|
-
hours_per_project = [(projects[t], tracked_hours[t]) for t in tracked_hours]
|
|
52
|
-
|
|
53
|
-
output = args.output
|
|
54
|
-
|
|
55
|
-
if output:
|
|
56
|
-
# If output filename provided, write to file
|
|
57
|
-
with open(output, "w") as out:
|
|
58
|
-
for h in sorted(hours_per_project, key=lambda x:x[1], reverse=True):
|
|
59
|
-
out.write(f"{h[0]}\t{h[1]}\n")
|
|
60
|
-
else:
|
|
61
|
-
# Otherwise, print out project names and tracked hours to stdout
|
|
62
|
-
for h in sorted(hours_per_project, key=lambda x:x[1], reverse=True):
|
|
63
|
-
print(f"{h[0]}\t{h[1]}")
|
|
64
|
-
|
|
65
|
-
if __name__ == "__main__":
|
|
66
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|