-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrapers.js
More file actions
80 lines (75 loc) · 1.94 KB
/
scrapers.js
File metadata and controls
80 lines (75 loc) · 1.94 KB
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
71
72
73
74
75
76
77
78
79
80
var db = require('./db.js');
var http = require('http');
exports.BABS = function() {
setInterval(function() {
var jsonReq = http.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
writeNewData(data);
});
});
jsonReq.on('error', function (e) {
console.log(e.message);
});
jsonReq.end();
}, 65000);
};
var options = {
host: 'bayareabikeshare.com',
path: '/stations/json',
method: 'GET',
contentType: 'application/json'
};
var writeNewData = function(data) {
data = JSON.parse(data);
for (var i = 0; i < data.stationBeanList.length; i++) {
var row = data.stationBeanList[i];
console.log(row);
row.executionTime = data.executionTime;
var query = "INSERT INTO stationstatuses ("
+ "executiontime,"
+ "stationid,"
+ "stationname,"
+ "availabledocks,"
+ "totaldocks,"
+ "latitude,"
+ "longitude,"
+ "statusvalue,"
+ "statuskey,"
+ "availablebikes,"
+ "staddress1,"
+ "staddress2,"
+ "city,"
+ "postalcode,"
+ "location,"
+ "altitude,"
+ "teststation,"
+ "lastcommunicationtime,"
+ "landmark"
+ ") VALUES (" +
"'" + row.executionTime + "'," +
row.id + "," +
"'" + row.stationName + "'," +
row.availableDocks + "," +
row.totalDocks + "," +
row.latitude + "," +
row.longitude + "," +
"'" + row.statusValue + "'," +
row.statusKey + "," +
row.availableBikes + "," +
"'" + row.stAddress1 + "'," +
"'" + row.stAddress2 + "'," +
"'" + row.city + "'," +
"'" + row.postalCode + "'," +
"'" + row.location + "'," +
"'" + row.altitude + "'," +
row.testStation + "," +
row.lastCommunicationTime + "," +
"'" + row.landMark + "'" +
");";
db.insertNewData(query);
}
};