1.1.0 • Published 3 years ago
@kenriortega/cuba-weather-javascript v1.1.0
Cuba Weather JavaScript
Application programming interface of the Cuba Weather project implemented in JavaScript.
Currently the weather information is obtained from the Cuban search engine www.redcuba.cu.
Install
npm install cuba-weather-javascript
You can also clone or download this repository and at the root of the project do:
git clone https://github.com/kenriortega/cuba-weather-javascript.git
Test
npm test
Package Red Cuba Client
const { RCApiClient, RCWeather } = require('../index')
async function main() {
let locationStr = 'Municipio Especial Isla de la Juventud'
try {
let res = await RCApiClient.get(locationStr)
let weather = new Weather(res.data.data)
console.log(weather.weathertoString())
} catch (err) {
let error = {
status: err.response.status,
statusText: err.response.statusText,
locationStr,
}
console.log(error)
}
}
main().catch(console.error)
Get weather from RDcuba by municipality
const {
RCApiClient,
RCWeather,
RED_CUBA_SOURCE,
MUNICIPALITIES,
UtilsService,
} = require('../index')
async function main() {
let locationStr = 'cerro'
let municipality = MUNICIPALITIES.find(
(municipality) => municipality.nameCured === locationStr
)
let bestSource = UtilsService.getBestDistanceByMunicipality(
municipality,
RED_CUBA_SOURCE
)
try {
let res = await RCApiClient.get(bestSource.name)
let weather = new RCWeather(res.data.data)
console.log(weather.weathertoString())
} catch (err) {
console.log(err)
}
}
main().catch(console.error)
1.1.0
3 years ago