-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOLD_getEventHistory.js
47 lines (42 loc) · 1.27 KB
/
OLD_getEventHistory.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
require("dotenv").config();
const cheerio = require("cheerio");
const axios = require("axios");
const mysql = require("mysql");
const delay = ms => new Promise(res => setTimeout(res, ms));
const connection = mysql.createConnection({
host: process.env.HOST,
user: process.env.USER,
password: process.env.PASSWORD,
database: process.env.DATABASE
});
function getHistory() {
// Will scrape the eventIDs for the last 10 events
// and add them to a Queue table on MySQL
axios
.get("https://www.meetup.com/seattle-coffee-club/events/past/")
.then(response => {
// Load the web page source code into a cheerio instance
const $ = cheerio.load(response.data);
console.log("Scraping EventIDs from Meetup");
$("a.eventCard--link").each((index, value) => {
var link = $(value).attr("href");
let eventID = link.replace(/\D/g, "");
console.log(eventID);
const insertSQL = `CALL spAddCCEventQueue (?)`;
connection.query(insertSQL, [eventID], function(
error,
results,
fields
) {
if (error) throw error;
});
});
});
}
const runHistoryScrape = async () => {
connection.connect();
getHistory();
await delay(4000);
connection.end();
};
runHistoryScrape();