Skip to content

Commit d8f5230

Browse files
author
Christian Strappazzon
committed
Added meetup integration
1 parent 298ae15 commit d8f5230

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

assets/js/meetup.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Fetch data from meetup.com API
3+
pythonmilano.xyz | @cstrap
4+
Credits: http://stackoverflow.com/a/1176810/1430290
5+
*/
6+
7+
var query = "select json.name, json.time, yes_rsvp_count, json.link from json where url=";
8+
var query_current = query + "'https://api.meetup.com/Python-Milano/events/'";
9+
var query_past = query + "'https://api.meetup.com/Python-Milano/events/?status=past'";
10+
11+
function YQLQuery(query, callback) {
12+
this.query = query;
13+
this.callback = callback || function(){};
14+
this.fetch = function() {
15+
if (!this.query || !this.callback) {
16+
throw new Error('YQLQuery.fetch(): Parameters may be undefined');
17+
}
18+
var scriptEl = document.createElement('script'),
19+
uid = 'yql' + +new Date(),
20+
encodedQuery = encodeURIComponent(this.query.toLowerCase()),
21+
instance = this;
22+
YQLQuery[uid] = function(json) {
23+
instance.callback(json);
24+
delete YQLQuery[uid];
25+
document.body.removeChild(scriptEl);
26+
};
27+
scriptEl.src = 'http://query.yahooapis.com/v1/public/yql?q=' + encodedQuery + '&format=json&callback=YQLQuery.' + uid;
28+
document.body.appendChild(scriptEl);
29+
};
30+
}
31+
32+
function get_event(payload) {
33+
if (!payload.query.results) {
34+
var pastEvents = new YQLQuery(query_past, get_event);
35+
pastEvents.fetch();
36+
return;
37+
}
38+
var obj = payload.query.results.json.slice(-1)[0].json;
39+
var date = new Date(parseInt(obj.time));
40+
var month = ['GENNAIO', 'FEBBRAIO', 'APRILE', 'MAGGIO', 'GIUGNO', 'LUGLIO', 'AGOSTO', 'SETTEMBRE', 'OTTOBRE', 'NOVEMBRE', 'DICEMBRE']
41+
result = {
42+
'topic': obj.name,
43+
'day': date.getDate(),
44+
'month': month[date.getMonth()],
45+
'link': obj.link,
46+
}
47+
$('#topic').text(result.topic);
48+
$('#day').text(result.day);
49+
$('#month').text(result.month);
50+
$('#meetup_link').attr('href', result.link);
51+
};
52+
53+
var currentEvent = new YQLQuery(query_current, get_event);
54+
currentEvent.fetch();

index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ <h1 class="lead">Sviluppatori e Appassionati di Python a Milano</h1>
5454
<div class="container text-center" id="next-meetup">
5555
<h4><i>>>> "Prossimo Meetup"</i></h4>
5656
<div id="calendar">
57-
<div id="month">APRILE</div>
58-
<div id="day"> 20 </div>
57+
<div id="month">NA</div>
58+
<div id="day"> NA </div>
5959
</div>
6060
<div id="meetup">
61-
<h2 class="thin">PyBirra - Text</h2>
61+
<h2 id="topic" class="thin">TBA</h2>
6262
<p class="text-muted">
63-
<a href="https://www.meetup.com/Python-Milano/events/239037916/" class="btn btn-action btn-lg">Partecipa!</a>
63+
<a id="meetup_link" href="https://www.meetup.com/Python-Milano/events/" class="btn btn-action btn-lg">Partecipa!</a>
6464
</p>
6565
</div>
6666
</div>
@@ -268,6 +268,7 @@ <h2 class="text-center">Supported by</h2>
268268
<script src="assets/js/jQuery.headroom.min.js"></script>
269269
<script src="assets/js/template.js"></script>
270270
<script src="assets/js/motto.js"></script>
271+
<script src="assets/js/meetup.js"></script>
271272

272273
</body>
273274
</html>

0 commit comments

Comments
 (0)