Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codingtuto/cweather-npm-
Package NPM de notre API Coding Weather
https://github.com/codingtuto/cweather-npm-
api codingteam nodejs npm weather
Last synced: 2 months ago
JSON representation
Package NPM de notre API Coding Weather
- Host: GitHub
- URL: https://github.com/codingtuto/cweather-npm-
- Owner: codingtuto
- License: mit
- Created: 2023-08-30T17:31:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-30T21:28:58.000Z (over 1 year ago)
- Last Synced: 2024-04-26T16:04:25.319Z (9 months ago)
- Topics: api, codingteam, nodejs, npm, weather
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/coding-weather
- Size: 16.6 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Coding Weather API (NPM)
[![GitHub Repo](https://img.shields.io/github/repo-size/codingtuto/cweather-npm-)](https://github.com/codingtuto/cweather-npm-)
[![GitHub Forks](https://img.shields.io/github/forks/codingtuto/cweather-npm-?style=social)](https://github.com/codingtuto/cweather-npm-/forks)
[![GitHub Stars](https://img.shields.io/github/stars/codingtuto/cweather-npm-?style=social)](https://github.com/codingtuto/cweather-npm-/stargazers)
[![GitHub Contributors](https://img.shields.io/github/contributors/codingtuto/cweather-npm-)](https://github.com/codingtuto/cweather-npm-/graphs/contributors)[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/codingtuto/cweather-npm-/Node.js%20CI)](https://github.com/codingtuto/cweather-npm-/actions/workflows/node.js.yml)
[![Coverage Status](https://coveralls.io/repos/github/codingtuto/cweather-npm-/badge.svg?branch=main)](https://coveralls.io/github/codingtuto/cweather-npm-?branch=main)
![Last Commit](https://img.shields.io/github/last-commit/codingtuto/cweather-npm-)[![npm](https://img.shields.io/npm/v/coding-weather)](https://www.npmjs.com/package/coding-weather)
[![npm](https://img.shields.io/npm/dw/coding-weather)](https://www.npmjs.com/package/coding-weather)Coding Weather
Note: Pour la documentation en francais, cliquer ici.
The Coding Weather Package is a Node.js package that provides a convenient way to fetch weather data using coordinates (latitude and longitude) from the CWeather API. It offers two modes of usage: the "City Mode" and the "Coordinates Mode". Additionally, you can access specific weather data fields such as temperature from the API response.
Installation
You can install the package using npm:
npm install coding-weather
Usage
City Mode
In this mode, you can use the
weather
function to retrieve weather data based on a city name.const { weather } = require('coding-weather');
const cityName = 'Mexico';
weather(cityName, undefined, 'en')
.then(weatherData => {
console.log('Weather Data (EN - City Mode):', weatherData);
})
.catch(error => {
console.error('Error (EN - City Mode):', error.message);
});// Response
{
lat: 48.87,
lon: 2.33,
weather: {
id: 1003,
main: 'Partly cloudy',
icon: '//cdn.weatherapi.com/weather/64x64/day/116.png'
},
current: {
last_updated_epoch: 1693413900,
last_updated: '2023-08-30 18:45',
temp_c: 18,
temp_f: 64.4,
is_day: 1,
wind_mph: 9.4,
wind_kph: 15.1,
wind_degree: 320,
wind_dir: 'NW',
pressure_mb: 1011,
pressure_in: 29.85,
precip_mm: 0,
precip_in: 0,
humidity: 56,
cloud: 75,
feelslike_c: 18,
feelslike_f: 64.4,
vis_km: 10,
vis_miles: 6,
uv: 6,
gust_mph: 12.3,
gust_kph: 19.8
},
location: {
name: 'Paris',
region: 'Ile-de-France',
country: 'France',
tz_id: 'Europe/Paris',
localtime_epoch: 1693414114,
localtime: '2023-08-30 18:48'
}
}Coordinates Mode
You can use the
weather
function to retrieve weather data based on coordinates (latitude and longitude). Specify the language as 'en' for English or 'fr' for French.const { weather } = require('coding-weather');
const latitude = 48.8567;
const longitude = 2.3508;weather(latitude, longitude, 'en') // English language
.then(weatherData => {
console.log('Weather Data by Coordinates (EN):', weatherData);
})
.catch(error => {
console.error('Error:', error.message);
});// Response
{
lat: 36.1,
lon: 120.37,
weather: {
id: 1000,
main: 'Clear',
icon: '//cdn.weatherapi.com/weather/64x64/night/113.png'
},
current: {
last_updated_epoch: 1693413900,
last_updated: '2023-08-31 00:45',
temp_c: 22,
temp_f: 71.6,
is_day: 0,
wind_mph: 2.2,
wind_kph: 3.6,
wind_degree: 257,
wind_dir: 'WSW',
pressure_mb: 1012,
pressure_in: 29.88,
precip_mm: 0,
precip_in: 0,
humidity: 78,
cloud: 0,
feelslike_c: 24.6,
feelslike_f: 76.2,
vis_km: 10,
vis_miles: 6,
uv: 1,
gust_mph: 4,
gust_kph: 6.5
},
location: {
name: 'Qingdao',
region: 'Shandong',
country: 'China',
tz_id: 'Asia/Shanghai',
localtime_epoch: 1693414109,
localtime: '2023-08-31 00:48'
}
}Accessing Specific Weather Data
To access specific weather data fields such as temperature, you can directly navigate through the response object returned by the API. Here's an example of how to access the temperature field:
weather(latitude, longitude, 'en')
.then(weatherData => {
const temperatureCelsius = weatherData.current.temp_c;
const temperatureFahrenheit = weatherData.current.temp_f;console.log(`Temperature (C): ${temperatureCelsius}`);
console.log(`Temperature (F): ${temperatureFahrenheit}`);
})
.catch(error => {
console.error('Error:', error.message);
});Documentation francaise
Coding Weather est un package Node.js qui permet de récupérer des données météorologiques en utilisant des coordonnées (latitude et longitude) à partir de l'API CWeather. Il propose deux modes d'utilisation : le "Mode Ville" et le "Mode Coordonnées". De plus, il est possible d'accéder à des champs spécifiques des données météorologiques, comme la température, à partir de la réponse de l'API.
Installation
Vous pouvez installer le package à l'aide de npm :
npm install coding-weather
Utilisation
Mode Ville
Dans ce mode, vous pouvez utiliser la fonction
weather
pour obtenir des données météorologiques en spécifiant le nom d'une ville. Vous pouvez choisir la langue 'fr' pour le français ou 'en' pour l'anglais.const { weather } = require('coding-weather');
const cityName = 'paris';
weather(cityName, undefined, 'fr')
.then(weatherData => {
console.log('Weather Data (FR - Mode Ville):', weatherData);
})
.catch(error => {
console.error('Erreur (FR - Mode Ville):', error.message);
});// Exemple de réponse JSON en français
{
lat: 48.87,
lon: 2.33,
meteo: {
id: 1003,
principal: 'Partiellement nuageux',
icone: '//cdn.weatherapi.com/weather/64x64/day/116.png'
},
actuel: {
dernier_maj_epoch: 1693413900,
dernier_maj: '2023-08-30 18:45',
temp_c: 18,
temp_f: 64.4,
est_jour: 1,
vitesse_vent_mph: 9.4,
vitesse_vent_kph: 15.1,
degre_vent: 320,
direction_vent: 'NW',
pression_mb: 1011,
pression_in: 29.85,
precip_mm: 0,
precip_in: 0,
humidite: 56,
nuage: 75,
sensation_c: 18,
sensation_f: 64.4,
visibilite_km: 10,
visibilite_miles: 6,
indice_uv: 6,
rafale_mph: 12.3,
rafale_kph: 19.8
},
lieu: {
nom: 'Paris',
region: 'Ile-de-France',
pays: 'France',
tz_id: 'Europe/Paris',
localtime_epoch: 1693414114,
localtime: '2023-08-30 18:48'
}
}Mode Coordonnées
Vous pouvez utiliser la fonction
weather
pour obtenir des données météorologiques en utilisant des coordonnées (latitude et longitude). Spécifiez la langue 'fr' pour le français ou 'en' pour l'anglais.const { weather } = require('coding-weather');
const latitude = 48.8567;
const longitude = 2.3508;weather(latitude, longitude, 'fr') // Langue française
.then(weatherData => {
console.log('Données Météo par Coordonnées (FR) :', weatherData);
})
.catch(error => {
console.error('Erreur :', error.message);
});// Exemple de réponse JSON en français
{
lat: 36.1,
lon: 120.37,
meteo: {
id: 1000,
principal: 'Clair',
icone: '//cdn.weatherapi.com/weather/64x64/night/113.png'
},
actuel: {
dernier_maj_epoch: 1693413900,
dernier_maj: '2023-08-31 00:45',
temp_c: 22,
temp_f: 71.6,
est_jour: 0,
vitesse_vent_mph: 2.2,
vitesse_vent_kph: 3.6,
degre_vent: 257,
direction_vent: 'WSW',
pression_mb: 1012,
pression_in: 29.88,
precip_mm: 0,
precip_in: 0,
humidite: 78,
nuage: 0,
sensation_c: 24.6,
sensation_f: 76.2,
visibilite_km: 10,
visibilite_miles: 6,
indice_uv: 1,
rafale_mph: 4,
rafale_kph: 6.5
},
lieu: {
nom: 'Qingdao',
region: 'Shandong',
pays: 'Chine',
tz_id: 'Asia/Shanghai',
localtime_epoch: 1693414109,
localtime: '2023-08-31 00:48'
}
}Accès à des Données Météorologiques Spécifiques
Pour accéder à des champs spécifiques des données météorologiques, comme la température, vous pouvez naviguer directement dans l'objet de réponse renvoyé par l'API. Voici un exemple d'accès au champ de température :
weather(latitude, longitude, 'fr')
.then(weatherData => {
const temperatureCelsius = weatherData.actuel.temp_c;
const temperatureFahrenheit = weatherData.actuel.temp_f;console.log(`Température (°C) : ${temperatureCelsius}`);
console.log(`Température (°F) : ${temperatureFahrenheit}`);
})
.catch(error => {
console.error('Erreur :', error.message);
});Licence
Ce projet est sous licence MIT.
This project is licensed under the MIT License.