Skip to content

Commit 57b2e1a

Browse files
committed
feat(toggl): project info file can override project name
1 parent 5267c05 commit 57b2e1a

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

.env.sample

Lines changed: 1 addition & 0 deletions
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+
PROJECT_INFO_FILE=data/project-info-sample.json
45
USER_INFO_FILE=data/user-info-sample.json

.gitignore

Lines changed: 1 addition & 0 deletions
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
Lines changed: 4 additions & 0 deletions
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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"\n",
1717
"DATA_DIR = Path(\"./data\")\n",
1818
"DATA_SOURCE = Path(os.environ.get(\"TOGGL_DATA\", \"./data/toggl-sample.csv\"))\n",
19+
"\n",
20+
"PROJECT_INFO_FILE = os.environ.get(\"PROJECT_INFO_FILE\")\n",
1921
"USER_INFO_FILE = os.environ.get(\"USER_INFO_FILE\")\n",
2022
"\n",
2123
"CLIENT_NAME = os.environ.get(\"HARVEST_CLIENT_NAME\")\n",
@@ -28,13 +30,13 @@
2830
" return pd.to_timedelta(pd.to_datetime(td, format=\"%H:%M:%S\").strftime(\"%H:%M:%S\"))\n",
2931
"\n",
3032
"\n",
31-
"def read_user_info():\n",
32-
" with open(USER_INFO_FILE, \"r\") as ui:\n",
33+
"def read_info_file(file):\n",
34+
" with open(file, \"r\") as ui:\n",
3335
" return json.load(ui)\n",
3436
"\n",
3537
"\n",
36-
"def write_user_info(info):\n",
37-
" 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",
3840
" json.dump(info, ui, indent=2)"
3941
]
4042
},
@@ -87,6 +89,31 @@
8789
"source[\"Task\"] = source[\"Task\"].astype(\"category\")"
8890
]
8991
},
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+
},
90117
{
91118
"cell_type": "code",
92119
"execution_count": null,
@@ -98,7 +125,7 @@
98125
"NOT_FOUND = \"NOT FOUND\"\n",
99126
"\n",
100127
"if USER_INFO_FILE:\n",
101-
" file_info = read_user_info()\n",
128+
" file_info = read_info_file(USER_INFO_FILE)\n",
102129
" USER_INFO.update(file_info)\n",
103130
" print(f\"User info: {', '.join(USER_INFO.keys())}\")"
104131
]
@@ -157,7 +184,7 @@
157184
"outputs": [],
158185
"source": [
159186
"if len(USER_INFO) > 0 and USER_INFO_FILE:\n",
160-
" write_user_info(USER_INFO)"
187+
" write_info_file(USER_INFO_FILE, USER_INFO)"
161188
]
162189
},
163190
{

0 commit comments

Comments
 (0)