GithubHelp home page GithubHelp logo

kira-kitsune / open-weather-image Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 963 KB

A npm package to create images from the open weather API

Home Page: https://www.npmjs.com/package/open-weather-image

License: MIT License

TypeScript 100.00%
open-weather-api open-weather-map-api weather

open-weather-image's Introduction

open-weather-image

open-weather-image is a image creation (base64 or buffer (png format)) to show current weather data of a provided area

Forecast data is loaded from OpenWeather API

The theme changes if it's daytime or nighttime as shown below

Daytime

Nighttime

Or alternatively you can include it with a forecast

WithForecast

Optionally if you don't like the default colours, you can customise the theme (Only with solid colours, all arguments are optional, gradients will be added in future version)

Installation

npm:

npm install open-weather-image

bun:

bun add open-weather-image

Usage

First you will need to register and account on OpenWeather to obtain an API key

Recommended to put your API key as an environment variable.

How to Start OpenWeather

Basic Usage

You can output with a buffer or base64 string. Default: "buffer"

Base 64:

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    output: 'base64',
});

Buffer:

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    output: 'buffer',
});

With Metric Units

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    units: 'metric',
});

With Imperial Units

Imperial

Omitting the units property will use the preferred temperature unit of the target country.

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Springfield',
    stateCode: 'OR',
    countryCode: 'US',
    units: 'imperial',
});

With Forecast

WithForecast

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImage({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    withForecast: true,
});

Choosing a Locale

Currently only English and German is supported, and tested with, feel free to contribute with other langauges within the i18n.ts file. Default: "en"

ChangingLocale

import { createWeatherImage } from "open-weather-image"

const image = await createWeatherImage({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    withForecast: true,
    locale: "de",
});

Possible Locales (All the ones that don't have full support are disabled)

af - Afrikaans
al - Albanian
ar - Arabic
az - Azerbaijani
bg - Bulgarian
ca - Catalan
cz - Czech
da - Danish
de - German (Full Support)
el - Greek
en - English (Full Support)
eu - Basque
fa - Persian (Farsi)
fi - Finnish
fr - French
gl - Galician
he - Hebrew
hi - Hindi
hr - Croatian
hu - Hungarian
id - Indonesian
it - Italian
ja - Japanese
kr - Korean
la - Latvian
lt - Lithuanian
mk - Macedonian
no - Norwegian
nl - Dutch
pl - Polish
pt - Portuguese
pt_br - Português Brasil
ro - Romanian
ru - Russian
sv, se - Swedish
sk - Slovak
sl - Slovenian
sp, es - Spanish
sr - Serbian
th - Thai
tr - Turkish
ua, uk - Ukrainian
vi - Vietnamese
zh_cn - Chinese Simplified
zh_tw - Chinese Traditional
zu - Zulu

With a Theme

WithTheme

import { createWeatherImage } from 'open-weather-image';

const myTheme = {
    dayThemeRight: '#373CC4',
    forecastBgTheme: '#242424',
    forecastBoxDivider: '#FFFFFF',
    dayThemeText: '#FF00FF',
    dayThemeSymbol: '#00FF00',
};

const image = await createWeatherImage({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    withForecast: true,
    theme: myTheme,
});

Importing the theme type in TypeScript

import type { Theme } from 'open-weather-image';

Default Theme

const defaultTheme = {
    dayThemeLeft: '#FFD982',
    dayThemeRight: '#5ECEF6',
    dayThemeText: 'black', // #000000
    dayThemeSymbol: 'black',
    nightThemeLeft: '#25395C',
    nightThemeRight: '#1C2A4F',
    nightThemeText: 'white', // #FFFFFF
    nightThemeSymbol: 'white',
    forecastBgTheme: '#DDDDDD',
    forecastBoxTheme: '#EEEEEE',
    forecastText: 'black',
    forecastSymbolColour: 'black',
    forecastBoxDivider: 'black',
};

Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested.

You are free to submit a PR to this repo, please fork first, please only communicate in English or German.

License

open-weather-image is available under the MIT license. See the LICENSE.md file for more info.

Copyright © 2022-2024 Kira Kitsune https://kirakitsune.com, All rights reserved.

open-weather-image's People

Contributors

corysalad avatar kira-kitsune avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

corysalad

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.