-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 1.02 KB
/
index.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
const fs = require('fs');
const path = require('path')
const request = require('request');
if (!fs.existsSync(getDownloadPath())) {
fs.mkdirSync(getDownloadPath());
}
request(getBigModelUrl(), {json: true}, (err, res, body) => {
if (err) return console.log(err);
const modelList = body.results;
modelList
.map(model => model.bigg_id)
.forEach(model => {
console.log(`Downloading ${generateSbmlFileName(model)}`);
request(getSbmlDownloadLink(model), {}, (err, res, body) => {
if (err) return console.log(err);
fs.writeFileSync(path.join(getDownloadPath(), generateSbmlFileName(model)), body);
}
);
});
});
function getBigModelUrl() {
return 'http://bigg.ucsd.edu/api/v2/models';
}
function getSbmlDownloadLink(model) {
return `http://bigg.ucsd.edu/static/models/${model}.xml`;
}
function generateSbmlFileName(model) {
return `${model}.xml`;
}
function getDownloadPath() {
return 'models';
}