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

Update the list of global events #625

Merged
merged 8 commits into from
Apr 11, 2016
Merged
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
26 changes: 9 additions & 17 deletions events/pull-meetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,20 @@ const defaults = {
}
const results = []

function clean (event) {
delete event.topics
delete event.urlname
delete event.category
delete event.id
}

function finish (events) {
// return console.log(JSON.stringify(events))
events.forEach((event) => {
if (!countryMap[event.country]) {
console.log(event)
throw new Error('Do not have map for ' + event.country)
}
const region = yml.getRegion(countryMap[event.country])
if (!region.meetups) region.meetups = []
clean(event)
if (!yml.isSoT(region.meetups, event.city, event.name)) {
yml.replace(region.meetups, 'name', event.name, event)
}
})
yml.save()
}
// This is nice when testing if you cache the response
// finish(JSON.parse(require('fs').readFileSync('./meetup.json').toString()))

function pull (opts) {
request(opts, (err, resp, body) => {
Expand All @@ -47,9 +36,12 @@ function pull (opts) {
body.results.forEach((result) => {
const title = result.name.toLowerCase()

if (title.includes('nodeschool')) return
if (title.includes('mongodb') && title.includes('node')) return
if (title.includes('find a tech job') && title.includes('node')) return
if (
title.includes('find a tech job') ||
title.includes('nodeschool') ||
/ mongodb (?:user group|meet ?up)$/.test(title) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not title.includes('mongodb')?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are some MongoDB+Node.js events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also a lot of irrelevant events like Angular Ember etc but it's kinda hard to have ONLY relevant Node.js events. This a flaw in Meetup categories and topics.

title.startsWith('mongodb ')
) return

results.push(result)
})
Expand All @@ -65,9 +57,9 @@ function pull (opts) {
pull(Object.assign({
url: 'https://api.meetup.com/2/groups',
qs: {
only: 'city,country,description,group_photo.photo_link,lat,link,lon,name',
key: process.env.MEETUP_TOKEN,
upcoming_events: true,
topic: 'nodejs',
category: 34
topic: 'nodeJS',
category_id: 34 // tech
}
}, defaults))
20 changes: 15 additions & 5 deletions events/pull-nodeschool.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,30 @@ request({
}

reg.chapters.forEach((chapter) => {
delete chapter.region
chapter.location = `${chapter.location}, ${chapter.country}`
if (chapter.country) {
chapter.location += `, ${chapter.country}`
}
delete chapter.country
delete chapter.region
yml.replace(store.nodeschools, 'name', chapter.name, chapter)
chapters.push(chapter)
})
})

function _geo () {
if (chapters.length === 0) { return yml.save() }
if (chapters.length === 0) {
return yml.save()
}

const chapter = chapters.shift()
geocoder.geocode(chapter.location, (err, res) => {
console.log(err, res)
if (err || !res.length) { return _geo() }
if (err || !res.length) {
console.error(
err && err.message || `Could not geocode location: ${chapter.location}`
)
return _geo()
}

chapter.lat = res[0].latitude
chapter.lon = res[0].longitude
_geo()
Expand Down
66 changes: 37 additions & 29 deletions events/yaml-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,35 @@ const fs = require('fs')
const path = require('path')

const p = path.join(__dirname, '..', 'locale', 'en', 'get-involved', 'events.md')
const lines = fs.readFileSync(p).toString().split('\n')
const begin = lines.indexOf('---') + 1
const end = lines.indexOf('---', begin)
const store = yaml.safeLoad(lines.slice(begin, end).join('\n'))

function getRegion (region) {
let reg
for (reg in store.regions) {
if (store.regions[reg].region === region) return store.regions[reg]

//
// Slice the file contents to get the YAML source code.
//
const contents = fs.readFileSync(p, { encoding: 'utf8' }).trim().slice(4, -4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment about slicing? (YAML head, I know, but it's not that obvious.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

const store = yaml.safeLoad(contents)

store.regions || (store.regions = [])

function getRegion (name) {
let region = store.regions.find((reg) => reg.region === name)

if (!region) {
region = { region: name }
store.regions.push(region)
}
reg = { region: region }
store.regions.push(reg)
return reg

return region
}

/**
* This function checks if an event has been manually edited to prevent it
* from being overwritten the next time event scripts are run.
*
* See https://github.com/nodejs/nodejs.org/pull/398.
*/
function isSoT (meetups, city, name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what's this source_of_truth? Can we find a better (function) name for that? Or at least a short comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a reference to #398.

for (let i = 0; i < meetups.length; i++) {
if (meetups[i].city === city && meetups[i].name === name) {
if (meetups[i].source_of_truth) {
return true
}
return false
}
}
return false
const meetup = meetups.find((evt) => evt.city === city && evt.name === name)
return meetup && meetup.source_of_truth
}

function removeEmpty (dict) {
Expand All @@ -39,19 +43,23 @@ function removeEmpty (dict) {
}

function replace (list, key, keyValue, value) {
const index = list.findIndex((elem) => elem[key] === keyValue)

removeEmpty(value)
for (let i = 0; i < list.length; i++) {
if (list[i][key] === keyValue) {
list[i] = value
return
}

if (index !== -1) {
list[index] = value
} else {
list.push(value)
}
list.push(value)
}

function save () {
const str = ['---', yaml.dump(store), '---'].join('\n')
fs.writeFileSync(p, str)
fs.writeFileSync(p, [
'---',
yaml.safeDump(store, { lineWidth: Infinity }),
'---'
].join('\n'))
}

exports.removeEmpty = removeEmpty
Expand Down
Loading