Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse unique locations from events #435

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ node_modules
# generated by gulp
feed.xml
projects.html
locations.json
52 changes: 51 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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'));
Loading