Git Product home page Git Product logo

location-weather-api's Introduction

Weather web app showing weather in Brooklyn

Location and weather API

How to use

First, fill out .env with the following:

APP_URL='https://yourapp.glitch.me'
API_KEY='this-can-be-anything-1234'

APP_URL is the url of the app that will be calling your API. (Be sure to remove any trailing slashes). You will also need to include API_KEY when making calls to your API. Make it something random and hard to guess.

Apply for API keys for OpenWeatherMap and Flickr and add them as well.

OWM_APP_ID='1234abcd5678efg9'
FLICKR_API_KEY='1234abcd5678efg9'

Now you can access your API at following endpoints:

yourapp.glitch.me/weather

This endpoint is fully automatic, you only need to provide the API key.

https://yourapp.glitch.me/weather?api_key=your-api-key-1234

The script will detect the IP address and the location and then loads the weather for the location.

Optionally you can pass a units parameter:

  • for temperature in Fahrenheit use units=imperial (this is the default if the units parameter is omited)
  • for temperature in Celsius use units=metric

Example:

https://yourapp.glitch.me/weather?api_key=your-api-key-1234&units=metric

Here's a shortened example response:

{
  "weather": {
    "coord": {
      "lon": -12.34,
      "lat": 98.76
    },
    "weather": [
      {
        "id": 800,
        "main": "Clear",
        "description": "clear sky"
      }
    ],
    "main": {
      "temp": 37.31,
      "pressure": 1030,
      "humidity": 48,
      "temp_min": 32,
      "temp_max": 43
    },
    "visibility": 16093,
    "wind": {
      "speed": 5.19,
      "deg": 189
    }
  },
  "location": {
    "city": "Brooklyn",
    "country": "United States",
    "countryCode": "US",
    "lon": -12.34,
    "lat": 98.76
  }
}

yourapp.glitch.me/background

You need to provide weather which is text used to search Flickr, and location as latitude, and longitude that will help filter images based on where they were taken.

Example request URL:

https://yourapp.glitch.me/background?api_key=your-api-key-1234&weather=cloudy&latitude=-12.34&longitude=98.76

Example response:

{
  "photos": {
    "page": 1,
    "pages": 1,
    "perpage": 250,
    "total": "140",
    "photo": [
      {
        "id": "32263946454",
        "owner": "25756794@N04",
        "secret": "48b91eb335",
        "server": "2504",
        "farm": 3,
        "title": "New York",
        "ispublic": 1,
        "isfriend": 0,
        "isfamily": 0,
        "url_l": "https://farm3.staticflickr.com/2504/32263946454_48b91eb335_b.jpg",
        "height_l": "1024",
        "width_l": "1024"
      },
      /* more photos... */
      ]
  },
  "stat": "ok"
}

Todo

  • add response caching

Powered by

Learn more

Created by @fourtonfish

location-weather-api's People

Contributors

stefanbohacek 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.