Last active
January 4, 2017 15:18
-
-
Save jbollacke/536f86871df184d8386cfb34a9b11cb7 to your computer and use it in GitHub Desktop.
POC to convert data from abfallplus api to iCalendar.
This file contains 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
/* | |
1. capture api key data using mitm | |
2. insert api key data | |
*/ | |
var request = require('request'); | |
var plist = require('plist'); | |
var icalToolkit = require('ical-toolkit'); | |
var headers = { | |
'User-Agent': '<capture it using MITM>', | |
'Cookie': '<capture it using MITM>', | |
'Cookie2': '$Version=1', | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
var options = { | |
url: 'https://app.abfallplus.de/struktur.xml.zip', | |
method: 'POST', | |
headers: headers, | |
gzip: true, | |
form: {'app_id': 'de.k4systems.egst', 'client': '<capture it using MITM>'} | |
} | |
request(options, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var builder = icalToolkit.createIcsFileBuilder(); | |
var result = plist.parse(body) | |
var categoriesMap = result.categories.reduce(function(map, category) { | |
map[category.id] = category.name; return map | |
}, {}) | |
result.dates.forEach(function(date) { | |
builder.events.push({ | |
allDay: true, | |
start: new Date(date.pickup_date), | |
end: new Date(date.pickup_date), | |
summary: categoriesMap[date.category_id], | |
uid: date.uuid, | |
location: date.notification_message | |
}); | |
}) | |
console.log(builder.toString()) | |
} | |
}) |
This file contains 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
{ | |
"name": "abfallplus-ics-adapter", | |
"version": "1.0.0", | |
"description": "POC to convert data from abfallplus api to iCalendar.", | |
"main": "abfallplus-ics-adapter.js", | |
"dependencies": { | |
"ical-toolkit": "^1.0.9", | |
"plist": "^2.0.1", | |
"request": "^2.79.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node server.js" | |
}, | |
"author": "Jan Bollacke <[email protected]>", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment