-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfredDataBaseTest.js
More file actions
44 lines (40 loc) · 1022 Bytes
/
fredDataBaseTest.js
File metadata and controls
44 lines (40 loc) · 1022 Bytes
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
const axios = require('Axios')
const fs = require("fs")
const sleep = require('sleep-promise')
let apiKey = '5f11050cc1fbd2254dcee4489d8ae9fa'
getSeriess(106).then(function(result){
console.log(result)
console.log(result.seriess.length)
fs.writeFile('./data/FREDcategory106Seriess.json', JSON.stringify(result, null, 4), function(err){
if(err){
console.log(err)
}else{
console.log("JSON saved")
}
})
})
function getSeriess(id){
return new Promise((resolve, reject) => {
let url = 'https://api.stlouisfed.org/fred/category/series?category_id='+id+'&api_key='+apiKey+'&file_type=json'
tryAgain2 = false
axios.get(url).catch(function(error){
if(error.response){
tryAgain2 = true
}else if(error.request){
console.log(error.request)
tryAgain2 = true
}else{
console.log('Error', error.message)
tryAgain2 = true
}
}).then(resp => {
if(!tryAgain2){
resolve(resp.data)
}else{
sleep(1000).then(function(){
resolve(getSeriess(id))
})
}
})
})
}