papi-projects 0.1.0__py3-none-any.whl
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/__init__.py +9 -0
- papi/mocks.py +76 -0
- papi/project.py +161 -0
- papi/tests/__init__.py +0 -0
- papi/tests/test_project.py +123 -0
- papi/tests/test_user.py +121 -0
- papi/tests/test_userdb.json +44 -0
- papi/tests/test_wrappers.py +108 -0
- papi/user.py +197 -0
- papi/wrappers.py +522 -0
- papi_projects-0.1.0.dist-info/METADATA +19 -0
- papi_projects-0.1.0.dist-info/RECORD +17 -0
- papi_projects-0.1.0.dist-info/WHEEL +4 -0
- papi_projects-0.1.0.dist-info/entry_points.txt +4 -0
- scripts/__init__.py +0 -0
- scripts/collatetogglhours.py +64 -0
- scripts/createtogglproject.py +78 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import warnings
|
|
3
|
+
from papi.wrappers import TogglTrackWrapper
|
|
4
|
+
from papi import config
|
|
5
|
+
from papi.project import Project
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
"""Main function of create-toggl-project script"""
|
|
9
|
+
|
|
10
|
+
# Set up argparse
|
|
11
|
+
parser = argparse.ArgumentParser()
|
|
12
|
+
parser.add_argument(
|
|
13
|
+
"-u", "--user_id", type=str, help="three-letter user ID, e.g. CRD", required=False
|
|
14
|
+
)
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"-g", "--grant_code", type=str, help="grant code, e.g. R12345", required=False
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"-n", "--name", type=str, help="short project name, e.g. 'RNA-seq analysis'", required=False
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"-p", "--project_id", type=str, help="full project ID, e.g. P2024-ABC-DEFG, if already generated", required=False
|
|
23
|
+
)
|
|
24
|
+
args = parser.parse_args()
|
|
25
|
+
|
|
26
|
+
# Set up Toggl Track API wrapper
|
|
27
|
+
#
|
|
28
|
+
# NOTE: you must have added Toggl Track API key and password, with
|
|
29
|
+
# variable names below to .env file in this directory
|
|
30
|
+
if not "TOGGL_TRACK_API_KEY" in config and not "TOGGL_TRACK_PASSWORD" in config:
|
|
31
|
+
warnings.warn("Please create a .env file with TOGGL_TRACK_API_KEY and TOGGL_TRACK_PASSWORD set!")
|
|
32
|
+
return
|
|
33
|
+
toggl_api_key = config["TOGGL_TRACK_API_KEY"]
|
|
34
|
+
toggl_api_password = config["TOGGL_TRACK_PASSWORD"]
|
|
35
|
+
toggl = TogglTrackWrapper(toggl_api_key, toggl_api_password)
|
|
36
|
+
|
|
37
|
+
# Tell wrapper which workspace to set as default
|
|
38
|
+
toggl.set_default_workspace("TF Data Science")
|
|
39
|
+
|
|
40
|
+
user_id = args.user_id
|
|
41
|
+
grant_code = args.grant_code
|
|
42
|
+
project_name = args.name
|
|
43
|
+
project_id = args.project_id
|
|
44
|
+
|
|
45
|
+
if not project_id and user_id:
|
|
46
|
+
# Create project instance, grant code and name are optional
|
|
47
|
+
if grant_code and project_name:
|
|
48
|
+
proj = Project(user_id=user_id, grant_code=grant_code, name=project_name)
|
|
49
|
+
elif grant_code and not project_name:
|
|
50
|
+
proj = Project(user_id=user_id, grant_code=grant_code)
|
|
51
|
+
elif not grant_code and project_name:
|
|
52
|
+
proj = Project(user_id=user_id, name=project_name)
|
|
53
|
+
else:
|
|
54
|
+
proj = Project(user_id=user_id)
|
|
55
|
+
elif not user_id and project_id:
|
|
56
|
+
# Create project instance, grant code and name are optional
|
|
57
|
+
if grant_code and project_name:
|
|
58
|
+
proj = Project(id=project_id, grant_code=grant_code, name=project_name)
|
|
59
|
+
elif grant_code and not project_name:
|
|
60
|
+
proj = Project(id=project_id, grant_code=grant_code)
|
|
61
|
+
elif not grant_code and project_name:
|
|
62
|
+
proj = Project(id=project_id, name=project_name)
|
|
63
|
+
else:
|
|
64
|
+
proj = Project(id=project_id)
|
|
65
|
+
else:
|
|
66
|
+
warnings.warn("Please provide either a three-letter user_id *or* a full project_id")
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
# Create project on Toggl Track
|
|
70
|
+
#
|
|
71
|
+
# If name and grant code were provided, then project name will
|
|
72
|
+
# look like P2024-ABC-WXYZ - RNA-seq analysis (R12345),
|
|
73
|
+
# otherwise it will just be the project ID
|
|
74
|
+
toggl_proj_id = toggl.create_project(proj, toggl.default_workspace_id)
|
|
75
|
+
print(f"Project '{toggl_proj_id}' created successfully!")
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
main()
|