This repository was archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetEventBriteEvents.js
More file actions
63 lines (54 loc) · 3.14 KB
/
getEventBriteEvents.js
File metadata and controls
63 lines (54 loc) · 3.14 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
const eventTemplate = "<div class=\"row card\"><div class=\"col-12\"><div class=\"row\"><div class=\"col-sm-4 col-lg-2 event-date\"><span class=\"event-date-month\">`month`</span><span class=\"event-date-day\">`day`</span><p><span class=\"event-date-start-time\">`eventStart``eventStartAmPm` - </span><span class=\"event-date-end-time\">`eventEnd``eventEndAmPm`</span></p></div><div class=\"col-sm-8 col-lg-10 event-title\"><span class=\"event-title\">`eventName`</span></div></div><div class=\"row\"><div class=\"col-md-12 col-lg-9 event-description\"><span class=\"event-description\">`eventDescription`</span></div><div class=\"col-md-12 col-lg-3 event-book-button\"><!-- Noscript content for added SEO --><noscript><a href=\"https://www.eventbrite.co.uk/e/programming-101-tickets-`eventId`\"rel=\"noopener noreferrer\" target=\"_blank\"></noscript><!-- You can customize this button any way you like --><button id=\"eventbrite-widget-modal-trigger-`eventId`\" class=\"btn btn-primary float-right\"type=\"button\">Register</button><noscript></a>Register for tickets on Eventbrite</noscript></div></div></div></div>";
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const ajaxSettings = {
"async": true,
"crossDomain": true,
"url": "https://www.eventbriteapi.com/v3/organizations/464103861019/events/",
"method": "GET",
"headers": {
"Authorization": "Bearer <key>",
"Content-Type": "application/json"
}
};
function ajaxDone(data) {
{
console.log(data);
content = "";
for (i = 0; i < data.events.length; i++) {
event = data.events[i]
startDate = new Date(event.start.utc);
endDate = new Date(event.end.utc);
var month = monthNames[startDate.getMonth()].substring(0, 3).toUpperCase();
var day = startDate.getDate();
var eventStart = startDate.getHours();
var eventEnd = endDate.getHours();
var eventName = event.name.text;
var eventDescription = event.description.text;
var eventId = event.id;
var eventStartAmPm = "am";
var eventEndAmPm = "am";
if (eventStart > 12) {
eventStart -= 12;
eventStartAmPm = "pm";
}
if (eventEnd > 12) {
eventEnd -= 12;
eventEndAmPm = "pm";
}
if (event.status === "live") {
content = content + eventTemplate
.replace("`month`", month)
.replace("`day`", day)
.replace("`eventStart`", eventStart)
.replace("`eventStartAmPm`", eventStartAmPm)
.replace("`eventEnd`", eventEnd)
.replace("`eventEndAmPm`", eventEndAmPm)
.replace("`eventName`", eventName)
.replace("`eventDescription`", eventDescription)
.replace("`eventId`", eventId);
}
}
$("#events").append(content);
}
}
$.ajax(ajaxSettings).done(ajaxDone);