|
|
|
|
import fetch from 'node-fetch';
|
|
|
|
|
import { promises as fs } from 'fs';
|
|
|
|
|
const eventFiles = process.argv.slice(3);
|
|
|
|
|
|
|
|
|
|
const later = (delay, value) =>
|
|
|
|
|
new Promise((resolve) => setTimeout(resolve, delay, value));
|
|
|
|
|
|
|
|
|
|
export const unix = (a) => parseInt(new Date(a).valueOf() / 1000, 10);
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
|
const root = '/home/zalox/src/acne/lib/derma';
|
|
|
|
|
|
|
|
|
|
let requests = [];
|
|
|
|
|
|
|
|
|
|
const promises = eventFiles.map(async (filename) => {
|
|
|
|
|
const path = `${root}/${filename}`;
|
|
|
|
|
const file_content = await fs.readFile(path, { encoding: 'utf-8' });
|
|
|
|
|
const j = JSON.parse(file_content);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < j.length; i++) {
|
|
|
|
|
let event = j[i];
|
|
|
|
|
let trondheim = event.event_place?.city?.id === '110429825645017';
|
|
|
|
|
const payload = {
|
|
|
|
|
canceled: false,
|
|
|
|
|
end: -1,
|
|
|
|
|
start: unix(new Date(event.time_range.start)),
|
|
|
|
|
draft: false,
|
|
|
|
|
facebook_id: event.id,
|
|
|
|
|
host: event.event_place?.name ?? '',
|
|
|
|
|
location: trondheim
|
|
|
|
|
? 'Trondheim, Norway'
|
|
|
|
|
: event.event_place?.city?.contextual_name ?? 'Trondheim, Norway',
|
|
|
|
|
name: event.name ?? 'NAME_MISSING',
|
|
|
|
|
ticket_url: event.event_buy_ticket_url ?? ''
|
|
|
|
|
};
|
|
|
|
|
requests.push(payload);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await Promise.all(promises);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < requests.length; i++) {
|
|
|
|
|
let event = requests[i];
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
'http://localhost:3333/events/?token=831411806230c7e950c4eeb226499ef92bb6bdc4157797929a0e16d133dc13a8',
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify(event),
|
|
|
|
|
headers: { 'Content-Type': 'application/json' }
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
console.log(res.status);
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
let k = {
|
|
|
|
|
__typename: 'Page',
|
|
|
|
|
contextual_name: 'Olavshallen',
|
|
|
|
|
city: {
|
|
|
|
|
cityContextualName: 'Trondheim, Norway',
|
|
|
|
|
id: '110429825645017',
|
|
|
|
|
contextual_name: 'Trondheim, Norway'
|
|
|
|
|
},
|
|
|
|
|
id: '149127815110411',
|
|
|
|
|
name: 'Olavshallen',
|
|
|
|
|
url: 'https://www.facebook.com/olavshallenas/',
|
|
|
|
|
__isNode: 'Page'
|
|
|
|
|
};
|