From dc69bfa6038dca71278b8028e38bc8c61845b0fc Mon Sep 17 00:00:00 2001 From: Benjamin Rupp Date: Wed, 7 Aug 2024 08:13:14 +0200 Subject: [PATCH] Parse unique locations from events We use all upcoming and all events within the last 52 weeks to figure out 'active' Hackergarten locations. The venue of the event is used as sponsor. Later on we can add all different venues of a location to the sponsors list. We parse the link of the meetup group from the event link with no fallback. TODOs: - The citiy in the title should be replaced by the city of the address. - Long and Lat should be determined using the address and the openstreetmap api (used in hero-geo-location npm package). - Use modern JS to simplify the code. --- .gitignore | 1 + gulpfile.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d9bc85e..1db6620 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ node_modules # generated by gulp feed.xml projects.html +locations.json diff --git a/gulpfile.js b/gulpfile.js index 819d22e..18b4a31 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -101,6 +101,56 @@ gulp.task('generate-xml', gulp.series('validate-events', function () { .pipe(gulp.dest('.')); })); +/** + * Generate the location json file based on the events. + */ +gulp.task('generate-locations', gulp.series('validate-events', function () { + + return gulp.src("./events.json") + .pipe(jsonlint()) + .pipe(jsonlint.failOnError()) + .pipe(jsonlint.reporter()) + .pipe(transform(function (contents) { + var oneYearAgo = new Date(); + oneYearAgo.setDate(oneYearAgo.getDate()-52*7); + var events = JSON.parse(contents); + var recentEvents = events.filter(function(event) { + return new Date(event.date) > oneYearAgo; + }); + var uniqueLocations = {}; + for (var i = 0; i < recentEvents.length; i++) { + if (!uniqueLocations[recentEvents[i].address]) { + uniqueLocations[recentEvents[i].address] = []; + } + uniqueLocations[recentEvents[i].address].push(recentEvents[i]); + } + var locations = []; + for (var address in uniqueLocations) { + // TODO: use https://www.npmjs.com/package/hero-geo-location search to get long, lat and city + locations.push({ + title: 'Hackergarten City', + sponsors: [uniqueLocations[address][0].venue], + link: getLink(uniqueLocations[address][0]), + lat: 0, + long: 0, + }); + } + console.log('Found', events.length, 'events at', locations.length, 'unique locations.'); + return JSON.stringify(locations); + })) + .pipe(rename("locations.json")) + .pipe(gulp.dest('.')); +})); + +function getLink(event) { + if(event.links && event.links[0]) { + var url = event.links[0].url; + if(url && url.includes('meetup.com')) { + return url.split('events')[0]; + } + } +} + /** * Generate the HTML file containing the top contributed projects. */ @@ -167,4 +217,4 @@ gulp.task('generate-projects', gulp.series('validate-events', function () { .pipe(gulp.dest('.')); })); -gulp.task('default', gulp.series('generate-xml', 'generate-projects')); +gulp.task('default', gulp.series('generate-xml', 'generate-projects', 'generate-locations'));