1.1.3 • Published 5 years ago
cuba-weather-javascript v1.1.3
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-javascriptYou can also clone or download this repository and at the root of the project do:
git clone https://github.com/cuba-weather/cuba-weather-javascript.gitTest
npm testPackage 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 RCWeather(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)