-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorkdev.io.js
executable file
·96 lines (76 loc) · 1.91 KB
/
corkdev.io.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
"use strict";
var _ = require("lodash"),
Q = require("q"),
request = require('request'),
cheerio = require('cheerio');
/**
*
* Get the Corkdev.io event object from api.meetup.com
*
* @return {Promise}
*
*/
var getCorkdevIOEvent = function(){
var dfd = Q.defer();
request({
method: 'GET',
uri: 'https://api.meetup.com/2/events?offset=0&format=json&limited_events=False&group_id=12225002&photo-host=public&page=20&fields=&order=time&status=past%2Cupcoming&desc=false&sig_id=128666892&sig=0ac44cfbc40e282bd4209de8880da2a9ecfb3ea7',
json: true,
}, function(error, response, body){
if(error){
dfd.reject(error);
}
else{
var events = body.results;
dfd.resolve(events[events.length-1]);
}
})
return dfd.promise;
};
/**
*
* Show meetup
*
* @param {Object} meetup
* @return
*
*/
var printEventInformation = function(meetup){
/// load html from description
var $ = cheerio.load(meetup.description);
/// set the description
var result = _.extend(meetup, {
description: $("p").map(function(){ return $(this).text(); }).get().join("\n")
});
/// show information
console.log([
"",
_.template("<%= venue.address_1 %>, <%= venue.city %>")(result),
_.template("<%= name %>")(result),
[ new Date(result.time).getHours(), ":", new Date(result.time).getMinutes() ].join(""),
"",
_.template("<%= description %>")(result),
"",
_.template("<%= event_url %>")(result),
""
].join("\n"));
};
/**
*
* Main function
* @return
*
*/
(function main(){
Q()
/// get the corkdevIO event
.then(getCorkdevIOEvent)
/// print event information
.then(printEventInformation)
/// error handling
.catch(function(e){
console.log(e);
process.exit(1);
});
})();