https://github.com/cuba-weather/cuba-weather-javascript
other package to contributed to cuba weather comunity
https://github.com/cuba-weather/cuba-weather-javascript
cuba-weather javascript
Last synced: 6 months ago
JSON representation
other package to contributed to cuba weather comunity
- Host: GitHub
- URL: https://github.com/cuba-weather/cuba-weather-javascript
- Owner: cuba-weather
- License: lgpl-3.0
- Created: 2020-06-17T01:00:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-16T20:47:23.000Z (over 1 year ago)
- Last Synced: 2025-03-21T13:12:44.033Z (7 months ago)
- Topics: cuba-weather, javascript
- Language: JavaScript
- Homepage:
- Size: 1.08 MB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Cuba Weather JavaScript
[](https://opensource.org/licenses/MIT)
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](https://www.redcuba.cu).
## Install
```bash
npm install cuba-weather-javascript
```You can also clone or download this repository and at the root of the project do:
```bash
git clone https://github.com/cuba-weather/cuba-weather-javascript.git
```## Test
```bash
npm test
```### Package Red Cuba Client
```javascript
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
```javascript
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)
```