Skip to content

A simple command line utility that displays live weather information for a particular ZIPCODE

Notifications You must be signed in to change notification settings

0xsouravm/weather-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather CLI

A simple command-line interface (CLI) application for retrieving weather information.

This project serves as a demonstration for the clap and reqwest crates.

Features

  • Get weather information for a specific zipcode
  • Login and logout functionality (TODO)

Installation

To install the Weather CLI, make sure you have Rust and Cargo installed on your system. Then, clone the repository and build the project:

git clone https://github.com/0xsouravm/weather-cli.git
cd weather-cli

cargo build --release
cargo install --path .
export PATH="$HOME/.cargo/bin:$PATH"

Usage

Get Weather Information

To get weather information for a specific zipcode:

weather <zipcode>

Replace with the ISO 3166 zipcode for which you want to retrieve weather information. Ex - E14,GB (London)

Login

To log in to the weather service:

weather login

Logout

To log out from the weather service:

weather logout

Configuration

The application uses environment variables for configuration. Create a .env file in the project root directory with the following variables:

GEOCODER_API_URL="http://api.openweathermap.org/geo/1.0/zip?zip={zip}&appid={api_key}"
WEATHER_API_URL="https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={long}&appid={api_key}"
OPEN_WEATHER_API_KEY=<your_api_key>

Replace the placeholder with your actual API key.

Project Structure

  • main.rs: Contains the main application logic and CLI structure
  • types.rs: Defines the types used in the application
  • api.rs: Handles API requests to the weather and geocoding services
  • env.rs: Exposes functions to fetch environment variables
  • cli.rs: Implements CLI-specific functionality
  • impl.rs: Contains additional implementation details to display the data

Dependencies

  • clap: For parsing command-line arguments
  • reqwest: For making HTTP requests
  • serde: For serializing and deserializing JSON data
  • tokio: For asynchronous runtime
  • dotenv: For loading environment variables from a file

About

A simple command line utility that displays live weather information for a particular ZIPCODE

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages