Created
March 25, 2022 09:25
-
-
Save mmodrow/46cca85f75a16eb073a98bcb56d1ea85 to your computer and use it in GitHub Desktop.
Generates a full dump of a given TimeCamp Time Tracking Report as JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ************************************************************************* | |
* Filter TimeCamp Time Tracking Report. | |
* ************************************************************************* | |
* Goto https://app.timecamp.com/app#/reports/projects_and_tasks/detailed | |
* Filter the desired time span etc. | |
* Inspect result of https://app.timecamp.com/time_tracking/ajax_get_reports_data | |
* in your browser dev tools network analysis. | |
* ************************************************************************* */ | |
var response = response ?? {}; // insert response from the ajax call in the header - can be several thousands of lines long. | |
var historyData = response.data; | |
var tagContentPattern = new RegExp(/^<[^>]+>(.*?)<[^>]+>$/); | |
var relevantDataRows = historyData.filter(x => x["Day_0"] && x["Timestamp_4"]) | |
.map(x => { | |
var timeSpan = x["Timestamp_4"].replace(tagContentPattern, "$1").split('-'); | |
return { | |
"date": x["Day_0"].replace(tagContentPattern, "$1"), | |
"timespanFrom": timeSpan[0], | |
"timespanTo": timeSpan[1] | |
} | |
}); | |
var timeTrackingData = {}; | |
for (const line of relevantDataRows) { | |
if (!timeTrackingData[line.date]) { | |
timeTrackingData[line.date] = []; | |
} | |
timeTrackingData[line.date].push([line.timespanFrom.padStart(5,'0'), line.timespanTo.padStart(5,'0')]); | |
timeTrackingData[line.date] = timeTrackingData[line.date].sort((a, b) => (a[0] > b[0]) ? 1 : -1); | |
} | |
console.log(JSON.stringify(timeTrackingData)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment