forked from otherplane/lisbon-blockchain-week
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchEvents.js
81 lines (76 loc) · 2.04 KB
/
fetchEvents.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
import Papa from 'papaparse'
import { getTimestampFromDateAndTime, convertTime12to24 } from './utils'
export function fetchEvents(fileUrl) {
return new Promise((resolve, reject) => {
Papa.parse(fileUrl, {
download: true,
header: true,
skipEmptyLines: true,
trimHeaders: true,
transformHeader: (h) => h.trim(),
complete(results) {
if (results.data) {
return resolve(
results.data.map(normalizeEvent).filter((event) => event)
)
} else {
return reject(results.errors)
}
},
})
})
}
function normalizeEvent(rawEvent) {
if (rawEvent['Title of your event']) {
const startTimestamp = getTimestampFromDateAndTime(
rawEvent['Event date'],
rawEvent['Starting time']
)
const endTimestamp = getTimestampFromDateAndTime(
rawEvent['Event date'],
rawEvent['End time']
)
return {
id: `${rawEvent['Title of your event']} ${startTimestamp}`,
sponsors: rawEvent['Sponsor(s)'],
speakers: rawEvent['Speaker(s)'],
eventType: rawEvent['Event type'],
title: rawEvent['Title of your event'],
description: rawEvent['Long description of your event'],
startTimestamp,
endTimestamp,
venue: rawEvent.Venue,
address: rawEvent.Address,
image: rawEvent.Image,
url: parseUrls(rawEvent['Event URL']),
urlNote: rawEvent['Url note'],
startTime: convertTime12to24(rawEvent['Starting time']),
endTime: convertTime12to24(rawEvent['End time']),
categories: rawEvent['Event type']
.split(',')
.map((category) => category.trim()),
}
} else {
return null
}
}
function parseUrls(url) {
if (url.includes(',')) {
const urls = url.split(',')
return urls.map((link) => {
if (link.includes('##')) {
return {
label: link.split('##')[0],
link: link.split('##')[1],
}
} else {
return {
label: 'Link 1',
link,
}
}
})
} else {
return url
}
}