-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_content.js
96 lines (82 loc) · 2.67 KB
/
update_content.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
93
94
95
96
const fs = require('fs')
const axios = require('axios')
const token = process.env.EVENTBRITE_API_TOKEN
const getEvents = async () => {
const config = {
method: 'get',
url: 'https://www.eventbriteapi.com/v3/organizations/6465941965/events/?status=live&page_size=100&order_by=start_asc',
headers: {
Authorization: `Bearer ${token}`
}
}
return await axios(config).catch((error) => { console.log(error) })
}
const getLocation = async (venueId) => {
const config = {
method: 'get',
url: `https://www.eventbriteapi.com/v3/venues/${venueId}`,
headers: { Authorization: `Bearer ${token}` }
}
return await axios(config).catch((error) => { console.log(error) })
}
const getSoVersion = async () => {
const config = {
method: 'get',
url: 'https://raw.githubusercontent.com/Security-Onion-Solutions/securityonion/2.4/main/VERSION'
}
return await axios(config).catch((error) => { console.log(error) })
}
const morgrifyEvents = async () => {
const eventRes = await getEvents()
const eventArr = []
for (const event of eventRes.data.events) {
if (event.name.text.toLowerCase().includes('conference')) { continue }
if (event.status === 'started') { continue }
let location = 'Unknown'
if (event.online_event) {
location = 'Virtual'
} else if (event.venue_id !== null) {
const locationRes = await getLocation(event.venue_id)
if (locationRes.data.address.localized_area_display !== null) {
location = locationRes.data.address.localized_area_display
} else {
location = locationRes.data.address.localized_address_display
}
}
eventArr.push({
name: event.name.text,
summary: event.summary,
start: event.start.utc,
end: event.end.utc,
location,
register_link: event.url
})
}
return eventArr
}
const writeJsonToFile = (filename, jsonData) => {
fs.writeFileSync(`./content/${filename}`, JSON.stringify(jsonData, null, 2))
}
const writeSoVersion = async () => {
const versionRes = await getSoVersion()
const filename = 'version.json'
const jsonData = { version: versionRes.data.replace('\n', '') }
console.log(`Writing SO version to ${filename}...`)
writeJsonToFile(filename, jsonData)
console.log('Done\n')
}
const updateEvents = async () => {
const jsonData = {
events: []
}
const filename = 'training_schedule.json'
jsonData.events = await morgrifyEvents()
console.log(`Writing ${jsonData.events.length} events to ${filename}...`)
writeJsonToFile(filename, jsonData)
console.log('Done\n')
}
const main = () => {
writeSoVersion().catch((error) => { console.log(error) })
updateEvents().catch(error => console.log(error))
}
main()