Skip to content

Commit 45bf259

Browse files
committed
Merge pull request #625 from nodejs/update/events-list
Update the list of global events
2 parents b28556c + ba8336d commit 45bf259

File tree

4 files changed

+6265
-33102
lines changed

4 files changed

+6265
-33102
lines changed

events/pull-meetup.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,20 @@ const defaults = {
1212
}
1313
const results = []
1414

15-
function clean (event) {
16-
delete event.topics
17-
delete event.urlname
18-
delete event.category
19-
delete event.id
20-
}
21-
2215
function finish (events) {
23-
// return console.log(JSON.stringify(events))
2416
events.forEach((event) => {
2517
if (!countryMap[event.country]) {
2618
console.log(event)
2719
throw new Error('Do not have map for ' + event.country)
2820
}
2921
const region = yml.getRegion(countryMap[event.country])
3022
if (!region.meetups) region.meetups = []
31-
clean(event)
3223
if (!yml.isSoT(region.meetups, event.city, event.name)) {
3324
yml.replace(region.meetups, 'name', event.name, event)
3425
}
3526
})
3627
yml.save()
3728
}
38-
// This is nice when testing if you cache the response
39-
// finish(JSON.parse(require('fs').readFileSync('./meetup.json').toString()))
4029

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

50-
if (title.includes('nodeschool')) return
51-
if (title.includes('mongodb') && title.includes('node')) return
52-
if (title.includes('find a tech job') && title.includes('node')) return
39+
if (
40+
title.includes('find a tech job') ||
41+
title.includes('nodeschool') ||
42+
/ mongodb (?:user group|meet ?up)$/.test(title) ||
43+
title.startsWith('mongodb ')
44+
) return
5345

5446
results.push(result)
5547
})
@@ -65,9 +57,9 @@ function pull (opts) {
6557
pull(Object.assign({
6658
url: 'https://api.meetup.com/2/groups',
6759
qs: {
60+
only: 'city,country,description,group_photo.photo_link,lat,link,lon,name',
6861
key: process.env.MEETUP_TOKEN,
69-
upcoming_events: true,
70-
topic: 'nodejs',
71-
category: 34
62+
topic: 'nodeJS',
63+
category_id: 34 // tech
7264
}
7365
}, defaults))

events/pull-nodeschool.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,30 @@ request({
2929
}
3030

3131
reg.chapters.forEach((chapter) => {
32-
delete chapter.region
33-
chapter.location = `${chapter.location}, ${chapter.country}`
32+
if (chapter.country) {
33+
chapter.location += `, ${chapter.country}`
34+
}
3435
delete chapter.country
36+
delete chapter.region
3537
yml.replace(store.nodeschools, 'name', chapter.name, chapter)
3638
chapters.push(chapter)
3739
})
3840
})
3941

4042
function _geo () {
41-
if (chapters.length === 0) { return yml.save() }
43+
if (chapters.length === 0) {
44+
return yml.save()
45+
}
46+
4247
const chapter = chapters.shift()
4348
geocoder.geocode(chapter.location, (err, res) => {
44-
console.log(err, res)
45-
if (err || !res.length) { return _geo() }
49+
if (err || !res.length) {
50+
console.error(
51+
err && err.message || `Could not geocode location: ${chapter.location}`
52+
)
53+
return _geo()
54+
}
55+
4656
chapter.lat = res[0].latitude
4757
chapter.lon = res[0].longitude
4858
_geo()

events/yaml-sync.js

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,35 @@ const fs = require('fs')
55
const path = require('path')
66

77
const p = path.join(__dirname, '..', 'locale', 'en', 'get-involved', 'events.md')
8-
const lines = fs.readFileSync(p).toString().split('\n')
9-
const begin = lines.indexOf('---') + 1
10-
const end = lines.indexOf('---', begin)
11-
const store = yaml.safeLoad(lines.slice(begin, end).join('\n'))
12-
13-
function getRegion (region) {
14-
let reg
15-
for (reg in store.regions) {
16-
if (store.regions[reg].region === region) return store.regions[reg]
8+
9+
//
10+
// Slice the file contents to get the YAML source code.
11+
//
12+
const contents = fs.readFileSync(p, { encoding: 'utf8' }).trim().slice(4, -4)
13+
const store = yaml.safeLoad(contents)
14+
15+
store.regions || (store.regions = [])
16+
17+
function getRegion (name) {
18+
let region = store.regions.find((reg) => reg.region === name)
19+
20+
if (!region) {
21+
region = { region: name }
22+
store.regions.push(region)
1723
}
18-
reg = { region: region }
19-
store.regions.push(reg)
20-
return reg
24+
25+
return region
2126
}
2227

28+
/**
29+
* This function checks if an event has been manually edited to prevent it
30+
* from being overwritten the next time event scripts are run.
31+
*
32+
* See https://github.com/nodejs/nodejs.org/pull/398.
33+
*/
2334
function isSoT (meetups, city, name) {
24-
for (let i = 0; i < meetups.length; i++) {
25-
if (meetups[i].city === city && meetups[i].name === name) {
26-
if (meetups[i].source_of_truth) {
27-
return true
28-
}
29-
return false
30-
}
31-
}
32-
return false
35+
const meetup = meetups.find((evt) => evt.city === city && evt.name === name)
36+
return meetup && meetup.source_of_truth
3337
}
3438

3539
function removeEmpty (dict) {
@@ -39,19 +43,23 @@ function removeEmpty (dict) {
3943
}
4044

4145
function replace (list, key, keyValue, value) {
46+
const index = list.findIndex((elem) => elem[key] === keyValue)
47+
4248
removeEmpty(value)
43-
for (let i = 0; i < list.length; i++) {
44-
if (list[i][key] === keyValue) {
45-
list[i] = value
46-
return
47-
}
49+
50+
if (index !== -1) {
51+
list[index] = value
52+
} else {
53+
list.push(value)
4854
}
49-
list.push(value)
5055
}
5156

5257
function save () {
53-
const str = ['---', yaml.dump(store), '---'].join('\n')
54-
fs.writeFileSync(p, str)
58+
fs.writeFileSync(p, [
59+
'---',
60+
yaml.safeDump(store, { lineWidth: Infinity }),
61+
'---'
62+
].join('\n'))
5563
}
5664

5765
exports.removeEmpty = removeEmpty

0 commit comments

Comments
 (0)