Skip to content

Commit

Permalink
Merge 7b6703d into 2517894
Browse files Browse the repository at this point in the history
  • Loading branch information
baron-chiu committed Jan 25, 2021
2 parents 2517894 + 7b6703d commit b9ad2a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data/taiwan-holiday-cache.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/opendata-tw.js
Expand Up @@ -23,6 +23,7 @@ class OpendataTW {
};

// TODO: fetch method rather than url
OpendataTW.url = 'https://data.ntpc.gov.tw/api/datasets/308DCD75-6434-45BC-A95F-584DA4FED251/json?size=2000';
OpendataTW.urlFirst1000 = 'https://data.taipei/api/v1/dataset/b0011e96-3fc3-43ec-8bf5-07fb46dd22bb?scope=resourceAquire&q=&limit=1000=&offset=0';
OpendataTW.urlSecond1000 = "https://data.taipei/api/v1/dataset/b0011e96-3fc3-43ec-8bf5-07fb46dd22bb?scope=resourceAquire&q=&limit=1000=&offset=1000";

module.exports = OpendataTW;
15 changes: 9 additions & 6 deletions lib/taiwan-holiday.js
Expand Up @@ -19,12 +19,15 @@ var TaiwanHoliday = {
this.cache = new Cache(path.resolve(temp_dir, 'taiwan-holiday-cache.json'));
return this.cache.load()
.catch(() => {
var ret;

return request(OpendataTW.url)
.then((str) => ret = JSON.parse(str))
.then((result) => this.cache.save(result))
.then(() => ret);
return Promise.all([request(OpendataTW.urlFirst1000), request(OpendataTW.urlSecond1000)])
.then(results => results.reduce((result, currentResult) => {
let json = JSON.parse(currentResult)
return result.concat(json.result.results)
}, []))
.then((result) => {
this.cache.save(result);
return result;
});
})
.then((json) => {
engine = new OpendataTW(json);
Expand Down

0 comments on commit b9ad2a9

Please sign in to comment.