Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasschroetler committed May 25, 2019
2 parents 403d768 + c8ebb9c commit 679c9a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions api/DB-StaDa.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const request = require('request');
//var tokens = ['fb06bdc6579f1a78ff221eb4612f45de', '0eb13363c4c00d4dffc0e277c210d6af', '8aa1bbd679c357273cbcdfd9526e78d9', 'ffa19eb6e54c688f45a278c5905ef35b']
var tokens = ['fb06bdc6579f1a78ff221eb4612f45de', '5ed35e0f3f963a87d041bff8688628f5', '3779406152f3222a68d9ceeeb4f24dbb']

exports.getStationInfo = function(id) {
exports.getStationInfo = function(id, i) {
return new Promise((resolve, reject) => {
request({
//url: 'https://api.deutschebahn.com/stada/v2/stations/'+brokenObject.objectId,
url: 'https://api.deutschebahn.com/stada/v2/stations/'+id,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer fb06bdc6579f1a78ff221eb4612f45de',
'Authorization': 'Bearer ' + tokens[i%3],
},
method: 'GET',
json: false,
Expand All @@ -19,7 +21,7 @@ exports.getStationInfo = function(id) {
resolve(JSON.parse(body).result[0].evaNumbers[0].number);
} catch (e) {
console.log(JSON.parse(body));
reject(e);
reject(e + i%3);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function ifoptToAss(ifopt) {

async function addNumbers() {
tempObjs.forEach((tempFac, i) => {
StaDa.getStationInfo(tempObjs[i].objectId).then((number) => {
StaDa.getStationInfo(tempObjs[i].objectId, i).then((number) => {
tempObjs[i].evaId = number
evaToIfopt(number).then(ifopt => {
tempObjs[i].ifopt = ifopt
Expand All @@ -167,4 +167,4 @@ async function addNumbers() {
})
.catch(e => {console.log(e)})
})
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"dependencies": {
"express": "4.17.0",
"cors": "2.8.5",
"curl": "0.1.4"
"curl": "0.1.4",
"csv-parser": "2.3.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 679c9a0

Please sign in to comment.