-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
479 changed files
with
86,286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// pass through api requests | ||
|
||
// http(s) modules | ||
const https = require('https'); | ||
|
||
// url parsing | ||
const queryString = require('querystring'); | ||
|
||
// return an express router | ||
module.exports = (req, res) => { | ||
// add out-going headers | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+, [email protected])'; | ||
headers.accept = req.headers.accept; | ||
|
||
// get query paramaters if the exist | ||
const queryParams = Object.keys(req.query).reduce((acc, key) => { | ||
// skip the paramater 'u' | ||
if (key === 'u') return acc; | ||
// add the paramter to the resulting object | ||
acc[key] = req.query[key]; | ||
return acc; | ||
}, {}); | ||
let query = queryString.encode(queryParams); | ||
if (query.length > 0) query = `?${query}`; | ||
|
||
// get the page | ||
https.get(`https://api.weather.gov${req.path}${query}`, { | ||
headers, | ||
}, (getRes) => { | ||
// pull some info | ||
const { statusCode } = getRes; | ||
// pass the status code through | ||
res.status(statusCode); | ||
|
||
// set headers | ||
res.header('content-type', getRes.headers['content-type']); | ||
// pipe to response | ||
getRes.pipe(res); | ||
}).on('error', (e) => { | ||
console.error(e); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// pass through api requests | ||
|
||
// http(s) modules | ||
const https = require('https'); | ||
|
||
// url parsing | ||
const queryString = require('querystring'); | ||
|
||
// return an express router | ||
module.exports = (req, res) => { | ||
// add out-going headers | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+, [email protected])'; | ||
headers.accept = req.headers.accept; | ||
|
||
// get query paramaters if the exist | ||
const queryParams = Object.keys(req.query).reduce((acc, key) => { | ||
// skip the paramater 'u' | ||
if (key === 'u') return acc; | ||
// add the paramter to the resulting object | ||
acc[key] = req.query[key]; | ||
return acc; | ||
}, {}); | ||
let query = queryString.encode(queryParams); | ||
if (query.length > 0) query = `?${query}`; | ||
|
||
// get the page | ||
https.get(`https://www.cpc.ncep.noaa.gov/${req.path}${query}`, { | ||
headers, | ||
}, (getRes) => { | ||
// pull some info | ||
const { statusCode } = getRes; | ||
// pass the status code through | ||
res.status(statusCode); | ||
|
||
// set headers | ||
res.header('content-type', getRes.headers['content-type']); | ||
res.header('last-modified', getRes.headers['last-modified']); | ||
// pipe to response | ||
getRes.pipe(res); | ||
}).on('error', (e) => { | ||
console.error(e); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// pass through api requests | ||
|
||
// http(s) modules | ||
const https = require('https'); | ||
|
||
// url parsing | ||
const queryString = require('querystring'); | ||
|
||
// return an express router | ||
module.exports = (req, res) => { | ||
// add out-going headers | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+, [email protected])'; | ||
headers.accept = req.headers.accept; | ||
|
||
// get query paramaters if the exist | ||
const queryParams = Object.keys(req.query).reduce((acc, key) => { | ||
// skip the paramater 'u' | ||
if (key === 'u') return acc; | ||
// add the paramter to the resulting object | ||
acc[key] = req.query[key]; | ||
return acc; | ||
}, {}); | ||
let query = queryString.encode(queryParams); | ||
if (query.length > 0) query = `?${query}`; | ||
|
||
// get the page | ||
https.get(`https://radar.weather.gov${req.path}${query}`, { | ||
headers, | ||
}, (getRes) => { | ||
// pull some info | ||
const { statusCode } = getRes; | ||
// pass the status code through | ||
res.status(statusCode); | ||
|
||
// set headers | ||
res.header('content-type', getRes.headers['content-type']); | ||
res.header('last-modified', getRes.headers['last-modified']); | ||
// pipe to response | ||
getRes.pipe(res); | ||
}).on('error', (e) => { | ||
console.error(e); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// turn a long array into a set of smaller chunks | ||
|
||
const chunk = (data, chunkSize = 10) => { | ||
const chunks = []; | ||
|
||
let thisChunk = []; | ||
|
||
data.forEach((d) => { | ||
if (thisChunk.length >= chunkSize) { | ||
chunks.push(thisChunk); | ||
thisChunk = []; | ||
} | ||
thisChunk.push(d); | ||
}); | ||
|
||
// final chunk | ||
if (thisChunk.length > 0) chunks.push(thisChunk); | ||
|
||
return chunks; | ||
}; | ||
|
||
module.exports = chunk; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// async https wrapper | ||
|
||
const https = require('https'); | ||
|
||
module.exports = (url) => new Promise((resolve, reject) => { | ||
const headers = {}; | ||
headers['user-agent'] = '(WeatherStar 4000+ data generator, [email protected])'; | ||
|
||
https.get(url, { | ||
headers, | ||
}, (res) => { | ||
if (res.statusCode === 200) { | ||
const buffers = []; | ||
res.on('data', (data) => buffers.push(data)); | ||
res.on('end', () => resolve(Buffer.concat(buffers).toString())); | ||
} else { | ||
console.log(res); | ||
reject(new Error(`Unable to get: ${url}`)); | ||
} | ||
}).on('error', (e) => { | ||
console.log(e); | ||
reject(e); | ||
}); | ||
}); |
Oops, something went wrong.