Skip to content

Commit 147532b

Browse files
committed
feat(toggl): project info file can override project name
1 parent 7b95809 commit 147532b

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

.env.sample

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
HARVEST_CLIENT_NAME=Client1
22
HARVEST_DATA=data/harvest-sample.csv
33
TOGGL_DATA=data/toggl-sample.csv
4+
TOGGL_PROJECT_INFO_FILE=data/toggl-project-info-sample.json
45
TOGGL_USER_INFO_FILE=data/toggl-user-info-sample.json

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ __pycache__
1010
*.egg-info
1111
notebooks/data/*
1212
!notebooks/data/harvest-sample.csv
13+
!notebooks/data/toggl-project-info-sample.json
1314
!notebooks/data/toggl-sample.csv
1415
!notebooks/data/toggl-user-info-sample.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Project1": "WT1-01 - Project1",
3+
"Project3": "WT3-01 - Project3"
4+
}

notebooks/toggl-to-harvest.ipynb

+32-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"DATA_DIR = Path(\"./data\")\n",
1818
"DATA_SOURCE = Path(os.environ.get(\"TOGGL_DATA\", \"./data/toggl-sample.csv\"))\n",
1919
"\n",
20+
"PROJECT_INFO_FILE = os.environ.get(\"TOGGL_PROJECT_INFO_FILE\")\n",
2021
"USER_INFO_FILE = os.environ.get(\"TOGGL_USER_INFO_FILE\")\n",
2122
"\n",
2223
"CLIENT_NAME = os.environ.get(\"HARVEST_CLIENT_NAME\")\n",
@@ -29,13 +30,13 @@
2930
" return pd.to_timedelta(pd.to_datetime(td, format=\"%H:%M:%S\").strftime(\"%H:%M:%S\"))\n",
3031
"\n",
3132
"\n",
32-
"def read_user_info():\n",
33-
" with open(USER_INFO_FILE, \"r\") as ui:\n",
33+
"def read_info_file(file):\n",
34+
" with open(file, \"r\") as ui:\n",
3435
" return json.load(ui)\n",
3536
"\n",
3637
"\n",
37-
"def write_user_info(info):\n",
38-
" with open(USER_INFO_FILE, \"w\") as ui:\n",
38+
"def write_info_file(file, info):\n",
39+
" with open(file, \"w\") as ui:\n",
3940
" json.dump(info, ui, indent=2)"
4041
]
4142
},
@@ -88,6 +89,31 @@
8889
"source[\"Task\"] = source[\"Task\"].astype(\"category\")"
8990
]
9091
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {},
96+
"outputs": [],
97+
"source": [
98+
"# cache of previously seen project information, keyed on Toggl project name\n",
99+
"PROJECT_INFO = {}\n",
100+
"\n",
101+
"if PROJECT_INFO_FILE:\n",
102+
" file_info = read_info_file(PROJECT_INFO_FILE)\n",
103+
" PROJECT_INFO.update(file_info)\n",
104+
" print(f\"Project info: {', '.join(PROJECT_INFO.keys())}\")"
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"metadata": {},
111+
"outputs": [],
112+
"source": [
113+
"# get cached project name if any\n",
114+
"source[\"Project\"] = source[\"Project\"].apply(lambda x: PROJECT_INFO.get(x, x))"
115+
]
116+
},
91117
{
92118
"cell_type": "code",
93119
"execution_count": null,
@@ -99,7 +125,7 @@
99125
"NOT_FOUND = \"NOT FOUND\"\n",
100126
"\n",
101127
"if USER_INFO_FILE:\n",
102-
" file_info = read_user_info()\n",
128+
" file_info = read_info_file(USER_INFO_FILE)\n",
103129
" USER_INFO.update(file_info)\n",
104130
" print(f\"User info: {', '.join(USER_INFO.keys())}\")"
105131
]
@@ -158,7 +184,7 @@
158184
"outputs": [],
159185
"source": [
160186
"if len(USER_INFO) > 0 and USER_INFO_FILE:\n",
161-
" write_user_info(USER_INFO)"
187+
" write_info_file(USER_INFO_FILE, USER_INFO)"
162188
]
163189
},
164190
{

0 commit comments

Comments
 (0)