rss-feeder-mobilizon/scrapers/adl.ts

43 lines
1.0 KiB
TypeScript

import * as fs from "fs";
// @ts-ignore
import fetch from 'node-fetch';
const puppeteer = require('puppeteer');
// get data from webpage
let options: any = {};
let scrappedData: any = {
pages: [],
titleList: null,
linkTitleEvent: null
};
options = {headless: false, devtools: true}
async function run() {
let tag = process.argv[2] ? process.argv[2] : '';
console.log('argument de tag', process.argv[2]);
const response = await fetch('https://www.agendadulibre.org/events.json?city=&near%5Blocation%5D=&near%5Bdistance%5D=&region=&tag=' + tag);
const data = await response.json();
console.log('évènements comptés: ', data.length);
let fileName = 'adl_json.json';
fs.writeFile(
`./output/${fileName}`,
JSON.stringify(data),
"utf8",
(err: any) => {
if (err) {
console.log(`Error writing file: ${err}`);
} else {
console.log(`File ${fileName} is written successfully!`);
}
}
);
}
run();