Skip to content

Commit

Permalink
Clean up the scripts to pull events data and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Mar 29, 2016
1 parent c834d59 commit 053ef73
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 64 deletions.
79 changes: 79 additions & 0 deletions events/country-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strict'

module.exports = {
EG: 'Africa',
ES: 'Africa',
KE: 'Africa',
MA: 'Africa',
MU: 'Africa',
NG: 'Africa',
ZA: 'Africa',
AE: 'Asia',
BD: 'Asia',
CN: 'Asia',
HK: 'Asia',
ID: 'Asia',
IL: 'Asia',
IN: 'Asia',
LB: 'Asia',
JP: 'Asia',
KR: 'Asia',
LK: 'Asia',
NP: 'Asia',
PH: 'Asia',
RU: 'Asia',
SA: 'Asia',
TH: 'Asia',
TW: 'Asia',
VN: 'Asia',
AT: 'Europe',
BE: 'Europe',
BY: 'Europe',
CH: 'Europe',
CZ: 'Europe',
DE: 'Europe',
DK: 'Europe',
EE: 'Europe',
FI: 'Europe',
FR: 'Europe',
GB: 'Europe',
GH: 'Europe',
GR: 'Europe',
HR: 'Europe',
HU: 'Europe',
IE: 'Europe',
IS: 'Europe',
IT: 'Europe',
LT: 'Europe',
LU: 'Europe',
ME: 'Europe',
MT: 'Europe',
NL: 'Europe',
NO: 'Europe',
PL: 'Europe',
PT: 'Europe',
RO: 'Europe',
RS: 'Europe',
SE: 'Europe',
SI: 'Europe',
SK: 'Europe',
TR: 'Europe',
UA: 'Europe',
CA: 'North America',
US: 'North America',
AR: 'Latin America',
BR: 'Latin America',
CL: 'Latin America',
CO: 'Latin America',
DO: 'Latin America',
EC: 'Latin America',
GT: 'Latin America',
MX: 'Latin America',
PA: 'Latin America',
PE: 'Latin America',
UY: 'Latin America',
VE: 'Latin America',
AU: 'South Pacific',
NZ: 'South Pacific',
SG: 'South Pacific'
}
63 changes: 38 additions & 25 deletions events/pull-meetup.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
const request = require('request').defaults({json: true, headers: {'user-agent': 'pull-meeting-0.1'}}),
url = 'https://api.meetup.com/2/groups',
auth = process.env.MEETUP_TOKEN,
qs = require('querystring'),
yml = require('./yaml-sync'),
opts =
{ topic: 'nodejs', category: 34, upcoming_events: true, key: auth
},
allresults = [],
u = url + '?' + qs.stringify(opts)

const countryMap =
{ ES: 'Africa', MU: 'Africa', NG: 'Africa', KE: 'Africa', ZA: 'Africa', MA: 'Africa', EG: 'Africa', IL: 'Asia', TH: 'Asia', KR: 'Asia', RU: 'Asia', ID: 'Asia', PH: 'Asia', IN: 'Asia', HK: 'Asia', CN: 'Asia', VN: 'Asia', TW: 'Asia', LK: 'Asia', NP: 'Asia', JP: 'Asia', AE: 'Asia', BD: 'Asia', LT: 'Europe', RS: 'Europe', HR: 'Europe', CZ: 'Europe', PT: 'Europe', TR: 'Europe', GR: 'Europe', DE: 'Europe', RO: 'Europe', MT: 'Europe', GH: 'Europe', IE: 'Europe', FI: 'Europe', SE: 'Europe', UA: 'Europe', AT: 'Europe', HU: 'Europe', CH: 'Europe', IS: 'Europe', GB: 'Europe', DK: 'Europe', EE: 'Europe', BE: 'Europe', NO: 'Europe', NL: 'Europe', FR: 'Europe', PL: 'Europe', SK: 'Europe', IT: 'Europe', SI: 'Europe', LU: 'Europe', BY: 'Europe', ME: 'Europe', CA: 'North America', US: 'North America', DO: 'Latin America', AR: 'Latin America', PE: 'Latin America', MX: 'Latin America', BR: 'Latin America', VE: 'Latin America', CL: 'Latin America', CO: 'Latin America', UY: 'Latin America', PA: 'Latin America', GT: 'Latin America', EC: 'Latin America', AU: 'South Pacific', SG: 'South Pacific', NZ: 'South Pacific'
'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
Expand All @@ -37,22 +36,36 @@ function finish (events) {
// This is nice when testing if you cache the response
// finish(JSON.parse(require('fs').readFileSync('./meetup.json').toString()))

function _go (u) {
request(u, (e, resp, body) => {
const results = body.results
results.forEach((result) => {
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.indexOf('nodeschool') !== -1) return
if (title.indexOf('mongodb') !== -1 && title.indexOf('node') === -1) return
if (title.indexOf('find a tech job') !== -1 && title.indexOf('node') === -1) return
// if (title.indexOf('node') !== -1) return allresults.push(result)
allresults.push(result)

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) {
_go(body.meta.next)
pull(Object.assign({ url: body.meta.next }, defaults))
} else {
finish(allresults)
finish(results)
}
})
}
_go(u)

pull(Object.assign({
url: 'https://api.meetup.com/2/groups',
qs: {
key: process.env.MEETUP_TOKEN,
upcoming_events: true,
topic: 'nodejs',
category: 34
}
}, defaults))
31 changes: 20 additions & 11 deletions events/pull-nodeschool.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
'use strict'

const request = require('request'),
yml = require('./yaml-sync'),
nodeGeocoder = require('node-geocoder'),
geoOpts = {
apiKey: process.env.MAPS_TOKEN,
formatter: null
},
geocoder = nodeGeocoder('google', 'https', geoOpts)

request('http://nodeschool.io/chapters/list.json', {json: true}, (e, resp, list) => {
if (e || resp.statusCode !== 200) throw (e || new Error('response not 200' + resp.statusCode))
const nodeGeocoder = require('node-geocoder')
const request = require('request')

const yml = require('./yaml-sync')
const pkg = require('../package')

const geocoder = nodeGeocoder('google', 'https', {
apiKey: process.env.MAPS_TOKEN,
formatter: null
})

request({
headers: { 'user-agent': `${pkg.name}/${pkg.version}` },
url: 'http://nodeschool.io/chapters/list.json',
json: true
}, (err, resp, list) => {
if (err || resp.statusCode !== 200) {
throw (err || new Error(`Invalid status code (${resp.statusCode})`))
}

let count = 0
const chapters = []

Expand Down
49 changes: 22 additions & 27 deletions events/yaml-sync.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
var yaml = require('js-yaml'),
fs = require('fs'),
path = require('path'),
p = path.join(__dirname, '..', 'locale', 'en', 'get-involved', 'events.md'),
buf = fs.readFileSync(p),
lines = buf.toString().split('\n'),
str = lines.slice(lines.indexOf('---') + 1, lines.indexOf('---', lines.indexOf('---') + 1)).join('\n'),
store = yaml.safeLoad(str)
'use strict'

exports.getRegion = (region) => {
let reg;
const yaml = require('js-yaml')
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]
}
Expand All @@ -17,15 +20,15 @@ exports.getRegion = (region) => {
return reg
}

exports.removeEmpty = (dict) => {
function removeEmpty (dict) {
for (const i in dict) {
if (!dict[i]) delete dict[i]
}
}

exports.replace = (list, key, keyValue, value) => {
exports.removeEmpty(value)
for (let i = 0;i < list.length;i++) {
function replace (list, key, keyValue, value) {
removeEmpty(value)
for (let i = 0; i < list.length; i++) {
if (list[i][key] === keyValue) {
list[i] = value
return
Expand All @@ -34,20 +37,12 @@ exports.replace = (list, key, keyValue, value) => {
list.push(value)
}

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

function rebalance () {
store.regions = store.regions.slice(0, 6)
exports.save()
}

function clearMeetups () {
store.regions.forEach((reg) => {
delete reg.meetups
})
exports.save()
}
// clearMeetups()
exports.removeEmpty = removeEmpty
exports.getRegion = getRegion
exports.replace = replace
exports.save = save
2 changes: 1 addition & 1 deletion scripts/release-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function fetchVersionPolicy (version) {
// matches the policy for a given version (Stable, LTS etc) in the changelog
// ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell
// 2015-12-04, Version 0.12.9 (LTS), @rvagg
const rxPolicy = new RegExp(`^(## )?\\d{4}-\\d{2}-\\d{2}, Version [^(].*\\(([^\\)]+)\\)`)
const rxPolicy = new RegExp('^(## )?\\d{4}-\\d{2}-\\d{2}, Version [^(].*\\(([^\\)]+)\\)')

return fetchChangelog(version)
.then((section) => {
Expand Down

0 comments on commit 053ef73

Please sign in to comment.