papi-projects 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: papi-projects
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: PAPI is an API for managing projects
5
5
  License: MIT
6
6
  Author: sandyjmacdonald
@@ -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
- times = {}
453
- for t in times_json:
454
- pid = t["pid"]
455
- seconds = t["duration"]
456
- hours = seconds / 60 / 60
457
- if pid not in times:
458
- times[pid] = hours
459
- else:
460
- times[pid] += hours
461
- return times
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
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "papi-projects"
3
- version = "0.2.2"
3
+ version = "0.2.4"
4
4
  description = "PAPI is an API for managing projects"
5
5
  authors = ["sandyjmacdonald <sandyjmacdonald@gmail.com>"]
6
6
  license = "MIT"
@@ -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()
@@ -81,7 +81,8 @@ def main():
81
81
 
82
82
  pyperclip.copy(project.id)
83
83
 
84
- logger.info(f"Project created with ID: {project.id} (copied to clipboard)")
84
+ print()
85
+ print(f"Project created with ID: {project.id} (copied to clipboard)")
85
86
 
86
87
  if __name__ == "__main__":
87
88
  main()
@@ -148,8 +148,6 @@ def main():
148
148
  # Create project on Toggl Track
149
149
  toggl_proj_id = toggl.create_project(project, toggl.default_workspace_id)
150
150
 
151
- pyperclip.copy(project.id)
152
-
153
151
  if enable_notion:
154
152
  # Set up Notion API wrapper
155
153
  #
@@ -170,9 +168,10 @@ def main():
170
168
  else:
171
169
  notion_proj_id = notion.create_project(project, user, notion_projects_db)
172
170
 
173
- pyperclip.copy(project.id)
171
+ pyperclip.copy(project.id)
174
172
 
175
- logger.info(f"Project created with ID: {project.id} (copied to clipboard)")
173
+ print()
174
+ print(f"Project created with ID: {project.id} (copied to clipboard)")
176
175
 
177
176
  if __name__ == "__main__":
178
177
  main()
@@ -77,7 +77,8 @@ def main():
77
77
 
78
78
  pyperclip.copy(project.id)
79
79
 
80
- logger.info(f"Project created with ID: {project.id} (copied to clipboard)")
80
+ print()
81
+ print(f"Project created with ID: {project.id} (copied to clipboard)")
81
82
 
82
83
  if __name__ == "__main__":
83
84
  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