Last active
March 7, 2024 05:11
-
-
Save gemanor/145544f6f0f2d8080d3f4e22aaf6ba21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // To run this script, you can either: | |
| // 1. Go to sessionize.com in your browser, open the browser console, and paste the following script | |
| // 2. Run it locally in Node.JS and comment the following imports in the begining of the file to use JSDom as a dom parser. | |
| // const jsdom = require("jsdom") | |
| // const { JSDOM } = jsdom | |
| // global.DOMParser = new JSDOM().window.DOMParser | |
| const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) | |
| const now = new Date(); | |
| (async () => { | |
| const response = await fetch('https://sessionize.com/sitemap/events.xml'); | |
| const xml = await response.text(); | |
| const parser = new DOMParser(); | |
| const doc = parser.parseFromString(xml, 'application/xml'); | |
| const urls = doc.querySelectorAll('urlset > url > loc'); | |
| const eventUrls = Array.from(urls).map(url => url.textContent); | |
| const events = await Promise.all(eventUrls.map(async (url, index) => { | |
| try { | |
| await sleep(index * 1000) | |
| const response = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } }); | |
| const html = await response.text(); | |
| const parser = new DOMParser(); | |
| const doc = parser.parseFromString(html, 'text/html'); | |
| const alreadyEnd = doc.querySelector('.alert.alert-danger'); | |
| if (alreadyEnd) return; | |
| const title = doc.querySelector('title').textContent.split(': Call for Speakers @ Sessionize.com')[0].trim(); | |
| const dateField = doc.querySelector('.m-b-md .fa-calendar').closest('.row').querySelector('h2').textContent; | |
| const date = new Date(dateField.split(',')[0].split('\n').join('').trim()); | |
| const multipleEvents = !!(dateField.split(',')?.length > 1); | |
| const description = doc.querySelector('meta[name="description"]').getAttribute('content'); | |
| const endDate = new Date(doc.querySelector('strong[data-date]').getAttribute('data-date').split('|')[0]); | |
| const location = doc.querySelector('.m-b-md .fa-map-marker')?.closest('.row').querySelector('h2').textContent.replace(/\s{2,}/g, ' ').trim('').split('\n').join('|'); | |
| const flightCovered = !!doc.querySelector('.m-b-md .fa-plane'); | |
| const hotelCovered = !!doc.querySelector('.m-b-md .fa-bed'); | |
| if (endDate < now) return; | |
| const event = { | |
| title, | |
| description, | |
| date: date.toDateString(), | |
| endDate: endDate().toDateString(), | |
| url, | |
| daysLeft: Math.ceil((endDate - now)/(1000*60*60*24)), | |
| daysBetween: Math.ceil((date - endDate)/(1000*60*60*24)), | |
| hotelCovered, | |
| flightCovered, | |
| location, | |
| multipleEvents | |
| }; | |
| console.log(event); | |
| return event; | |
| } catch (error) { | |
| console.log('--- ERROR ---'); | |
| console.log(url); | |
| console.log(error); | |
| console.log('--- END OF ERROR ---'); | |
| } | |
| })); | |
| console.log('--- DONE ---'); | |
| console.log(JSON.stringify(events.filter((e) => e !== undefined))); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment