cuba-weather / cuba-weather-javascript

other package to contributed to cuba weather comunity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cuba Weather JavaScript

License: 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.

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/cuba-weather/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 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)

About

other package to contributed to cuba weather comunity

License:GNU Lesser General Public License v3.0


Languages

Language:JavaScript 100.0%