-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcombinedetails.js
152 lines (133 loc) · 4.86 KB
/
combinedetails.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const fs = require('fs');
const ical = require('ical-generator');
function main()
{
var events = JSON.parse(fs.readFileSync("./files/events.min.json"));
fs.readdir("files/temp", function (err, files) {
if (err) {
return console.log('Unable to scan directory: ' + err);
}
files.forEach(f =>
{
var data = JSON.parse(fs.readFileSync("./files/temp/" + f));
events.forEach(e =>
{
if (e.eventID == data.id)
{
// add always generic data as 'generic' block in 'extraData' (available for all possible events)
if (data.type == "generic")
{
if (e.extraData === null) {
e.extraData = {};
}
e.extraData.generic = data.data;
}
// add event specific extra data. Block named as event type name
if (data.type == "research-breakthrough")
{
if (e.extraData === null) {
e.extraData = {};
}
e.extraData.breakthrough = data.data;
}
else if (data.type == "pokemon-spotlight-hour")
{
if (e.extraData === null) {
e.extraData = {};
}
e.extraData.spotlight = data.data
}
else if (data.type == "community-day")
{
if (e.extraData === null) {
e.extraData = {};
}
e.extraData.communityday = data.data
}
else if (data.type == "raid-battles")
{
if (e.extraData === null) {
e.extraData = {};
}
e.extraData.raidbattles = data.data
}
}
});
});
fs.writeFile('files/events.json', JSON.stringify(events, null, 4), err => {
if (err) {
console.error(err);
return;
}
});
fs.writeFile('files/events.min.json', JSON.stringify(events), err => {
if (err) {
console.error(err);
return;
}
});
generateCalendars(events);
fs.rm("files/temp", { recursive: true }, (err) => {
if (err) { throw err; }
});
});
}
function generateCalendars(events) {
const leekDuckFavIconUrl = "https://leekduck.com/assets/img/favicon/favicon-16x16.png";
const generatorName = "ScrapedDuck";
const generatorUrl = "https://github.com/bigfoott/ScrapedDuck";
const icalMeta = [
["x-origin", "https://leekduck.com/events/"],
["x-generator", generatorName],
["x-generator-url", generatorUrl],
];
const icals = new Map();
icals.set("all", ical.default({ name: "Pokémon Go — All Events", description: "All Pokémon Go events.", x: icalMeta }));
events.forEach(e => {
if (!icals.has(e.eventType)) {
icals.set(e.eventType, ical.default({ name: `Pokémon Go — ${e.heading}`, description: `Pokémon Go ${e.heading} events.`, x: icalMeta }));
}
const calAll = icals.get("all");
const calType = icals.get(e.eventType);
const calEventTitle = `${e.heading} — ${e.name}`
const calEvent = {
start: e.start,
end: e.end,
id: `scraped-duck-${e.eventID}`,
summary: calEventTitle,
description: `<a href="${e.link}">${e.name}</a>`,
categories: [{ name: e.heading }],
url: e.link,
organizer: { name: "LeekDuck c/o ScrapedDuck" },
x: [
["IMAGE", e.image],
["X-GOOGLE-CALENDAR-CONTENT-TITLE", calEventTitle],
["X-GOOGLE-CALENDAR-CONTENT-ICON", leekDuckFavIconUrl],
["X-GOOGLE-CALENDAR-CONTENT-URL", e.image],
["X-GOOGLE-CALENDAR-CONTENT-TYPE", "image/*"],
],
};
calAll.createEvent(calEvent);
calType.createEvent(calEvent);
});
if (!fs.existsSync('files/calendars'))
fs.mkdirSync('files/calendars');
for (const [key, cal] of icals) {
cal.prodId({ company: generatorName, product: "Scraped LeekDuck Events", language: "EN" })
fs.writeFile(`files/calendars/${key}.ics`, cal.toString(), err => {
if (err) {
console.error(err);
return;
}
});
}
}
try
{
main();
}
catch (e)
{
console.error("ERROR: " + e);
process.exit(1);
}