-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathpull-meetup.js
More file actions
73 lines (62 loc) · 1.81 KB
/
Copy pathpull-meetup.js
File metadata and controls
73 lines (62 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict'
const request = require('request')
const countryMap = require('./country-map')
const yml = require('./yaml-sync')
const pkg = require('../package')
const defaults = {
headers: { 'user-agent': `${pkg.name}/${pkg.version}` },
json: true
}
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, 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) => {
if (err || resp.statusCode !== 200) {
throw (err || new Error(`Invalid status code (${resp.statusCode})`))
}
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
results.push(result)
})
if (body.meta.next) {
pull(Object.assign({ url: body.meta.next }, defaults))
} else {
finish(results)
}
})
}
pull(Object.assign({
url: 'https://api.meetup.com/2/groups',
qs: {
key: process.env.MEETUP_TOKEN,
upcoming_events: true,
topic: 'nodejs',
category: 34
}
}, defaults))