-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdice_scrap.js
70 lines (58 loc) · 1.83 KB
/
dice_scrap.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
var http = require('http');
var nunjucks = require('nunjucks');
var nunjucksRender = require('gulp-nunjucks-render');
var data = require('gulp-data');
var gulp = require('gulp');
var path = require('path');
var PATH_TO_TEMPLATES = '.' ;
nunjucks.configure( PATH_TO_TEMPLATES, {
autoescape: true,
express: app
} ) ;
app.use(express.static(path.join(__dirname, 'public')));
const diceUrl = "https://dice.fm/artist/";
var events = [];
var urls = [];
var artists = ["traams","queens-of-the-stone-age","the-big-moon"];
// if not in artist then use https://dice.fm/_data/search/events;query=our-girl
for(artist in artists){
urls.push(diceUrl+artists[artist]);
}
//var $ = cheerio.load(fs.readFileSync('dice.html'));
for(u in urls){
var url = urls[u];
console.log("Getting gigs from " + url);
request.get(url, (error, response, body) => {
//TODO: if error then break
var $ = cheerio.load(body,{
ignoreWhitespace: false,
xmlMode: true
});
var artistsEvents = $('script[type="application/ld+json"]').html();
var artistsEvents = JSON.parse(artistsEvents);
var es = artistsEvents[0]['event'];
for(var e in es) {
var event = es[e][0];
events.push({
name : event['name'],
image : event['image'],
ticket : event['url'],
startDate : Date(event['doorTime']),
venue : event['location']['name'],
price : event['offers'][0]['price'],
address : event['location']['address']
});
}
});
}
app.get( '/', function( req, res ) {
//console.log({events:JSON.parse(events)});
console.log("Rendering html with events");
return res.render('test.html', {events: events});
});
app.listen( 8000 );