You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
1.8 KiB

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));
(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: parseInt(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'
};