Giter Club home page Giter Club logo

weather-app's Introduction

Weather App

Features:

  • Get current weather information for a given city
  • Get current weather information for multiple cities
  • Get weather statistics
  • Display live weather stats
  • Display a live weather map

installation

prerequisite

  • PHP 8.2 or higher
  • composer
  • MYSQL

install

  1. Clone the repository
git clone https://github.com/MohAlkurdi/weather-app.git && cd weather-app
  1. Configure Environment Variables:
cp .env.example .env

Don't forget to add your credentials for weatherAPI and windy

WEATHER_API_KEY=<WEATHER_API_KEY>
WINDY_API_KEY=<WINDY_API_KEY>
  1. Install Composer Dependencies:
composer install
  1. Generate Application Key:
php artisan key:generate
  1. Start the Development Server:
php artisan serve

API Reference

Get Weather Information By City Name

GET /api/weather/:city
Parameter Type Description
city string Required. City Name
  • The app will check the cache first, if not found, it will call the API
Response
{
    "location": {
        "name": "Jeddah",
        "region": "Makkah",
        "country": "Saudi Arabia",
        "lat": 21.52,
        "lon": 39.22,
        "tz_id": "Asia/Riyadh",
        "localtime_epoch": 1710282423,
        "localtime": "2024-03-13 1:27"
    },
    "current": {
        "last_updated_epoch": 1710281700,
        "last_updated": "2024-03-13 01:15",
        "temp_c": 28,
        "temp_f": 82.4,
        "is_day": 0,
        "condition": {
            "text": "Clear",
            "icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
            "code": 1000
        },
        "wind_mph": 3.8,
        "wind_kph": 6.1,
        "wind_degree": 340,
        "wind_dir": "NNW",
        "pressure_mb": 1012,
        "pressure_in": 29.88,
        "precip_mm": 0,
        "precip_in": 0,
        "humidity": 48,
        "cloud": 0,
        "feelslike_c": 30,
        "feelslike_f": 86.1,
        "vis_km": 10,
        "vis_miles": 6,
        "uv": 1,
        "gust_mph": 8.3,
        "gust_kph": 13.3
    }
}

Get Weather Information For Multiple Cities

POST /api/weather/bulk
  • Request Body
{
    "cities": ["Makkah", "Riyadh", "Jeddah"]
}
Response
[
    {
        "location": {
            "name": "Makkah",
            "region": "Makkah",
            "country": "Saudi Arabia",
            "lat": 21.43,
            "lon": 39.83,
            "tz_id": "Asia/Riyadh",
            "localtime_epoch": 1710283965,
            "localtime": "2024-03-13 1:52"
        },
        "current": {
            "last_updated_epoch": 1710283500,
            "last_updated": "2024-03-13 01:45",
            "temp_c": 28,
            "temp_f": 82.4,
            "is_day": 0,
            "condition": {
                "text": "Clear",
                "icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
                "code": 1000
            },
            "wind_mph": 3.8,
            "wind_kph": 6.1,
            "wind_degree": 340,
            "wind_dir": "NNW",
            "pressure_mb": 1012,
            "pressure_in": 29.88,
            "precip_mm": 0,
            "precip_in": 0,
            "humidity": 48,
            "cloud": 0,
            "feelslike_c": 29.7,
            "feelslike_f": 85.5,
            "vis_km": 10,
            "vis_miles": 6,
            "uv": 1,
            "gust_mph": 8.3,
            "gust_kph": 13.3
        }
    },
    {
        "location": {
            "name": "Riyadh",
            "region": "Ar Riyad",
            "country": "Saudi Arabia",
            "lat": 24.64,
            "lon": 46.77,
            "tz_id": "Asia/Riyadh",
            "localtime_epoch": 1710283879,
            "localtime": "2024-03-13 1:51"
        },
        "current": {
            "last_updated_epoch": 1710283500,
            "last_updated": "2024-03-13 01:45",
            "temp_c": 15,
            "temp_f": 59,
            "is_day": 0,
            "condition": {
                "text": "Clear",
                "icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
                "code": 1000
            },
            "wind_mph": 2.2,
            "wind_kph": 3.6,
            "wind_degree": 10,
            "wind_dir": "N",
            "pressure_mb": 1022,
            "pressure_in": 30.18,
            "precip_mm": 0,
            "precip_in": 0,
            "humidity": 33,
            "cloud": 0,
            "feelslike_c": 14.8,
            "feelslike_f": 58.6,
            "vis_km": 10,
            "vis_miles": 6,
            "uv": 1,
            "gust_mph": 9.4,
            "gust_kph": 15
        }
    },
    {
        "location": {
            "name": "Jeddah",
            "region": "Makkah",
            "country": "Saudi Arabia",
            "lat": 21.52,
            "lon": 39.22,
            "tz_id": "Asia/Riyadh",
            "localtime_epoch": 1710283893,
            "localtime": "2024-03-13 1:51"
        },
        "current": {
            "last_updated_epoch": 1710283500,
            "last_updated": "2024-03-13 01:45",
            "temp_c": 28,
            "temp_f": 82.4,
            "is_day": 0,
            "condition": {
                "text": "Clear",
                "icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
                "code": 1000
            },
            "wind_mph": 3.8,
            "wind_kph": 6.1,
            "wind_degree": 340,
            "wind_dir": "NNW",
            "pressure_mb": 1012,
            "pressure_in": 29.88,
            "precip_mm": 0,
            "precip_in": 0,
            "humidity": 48,
            "cloud": 0,
            "feelslike_c": 30,
            "feelslike_f": 86.1,
            "vis_km": 10,
            "vis_miles": 6,
            "uv": 1,
            "gust_mph": 8.3,
            "gust_kph": 13.3
        }
    }
]

Get Weather Stats

GET /api/weather/statistics/:city
Parameter Type Description
city string Required. City Name
Response
{
    "max_temp": 31.4,
    "min_temp": 26.6,
    "avg_temp": 28.5,
    "condition": "Sunny"
}

Live Weather stats & map

Live Weather Stats

visit http://localhost:8000/live?city=Makkah

screenshot-20240313-005500


Live Radar Weather Map

visit http://localhost:8000/live-radar

screenshot

Testing

php artisan test

weather-app's People

Contributors

mohalkurdi avatar

Watchers

 avatar

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.