Middleware for https://api.weather.gov/

Chandler Lofland d113ea6247 Merge pull request #1 from chand1012/dependabot/npm_and_yarn/prettier-2.0.5 4 weeks ago
.gitignore 33e03d6ea4 add package lock 2 months ago
.prettierrc f8372b4b26 added files 2 months ago
LICENSE f8372b4b26 added files 2 months ago
README.md 51d3fb0ca7 updated readme 1 month ago
index.js 1d16a899ec added better error handling 1 month ago
package-lock.json 004567083e Bump prettier from 1.19.1 to 2.0.5 4 weeks ago
package.json 004567083e Bump prettier from 1.19.1 to 2.0.5 4 weeks ago
webpack.config.js 1465834531 formated javascript 2 months ago
wrangler.toml f8372b4b26 added files 2 months ago


Weather Worker

This was a simple project meant for me to teach myself how to use a serverless system, in this case Cloudflare Workers. This acts as middle ware for https://api.weather.gov/, so it will only work for the US and its territories.

To use

Simply submit a POST request to the url at https://weather-api.chand1012.workers.dev/. Here is a cURL example:

curl -XPOST -H "Content-type: application/json" -d '{"lat": 38.9, "lng": -77}' 'https://weather-api.chand1012.workers.dev'

Python Example:

import requests

lat = 41
lng = -71

req = requests.post("https://weather-api.chand1012.workers.dev/", headers={'content-type':'application/json'}, json={'lat':lat, 'lng':lng})


This will return the forecasts for the next 7 days for the given forecast. If you want a simple python class with functions to work with this, here is the snippet of code I use for my Discord Weather Bot:

class WorkerWeatherSearch():
    def __init__(self):
        self.lat = 41.08
        self.lng = -81.51
        self.base_url = "https://weather-api.chand1012.workers.dev"
        self.json = None
        self.forecasts = []

    def search(self, lat, lng):
        self.lat = lat
        self.lng = lng
        req = requests.post(self.base_url, headers={'content-type':'application/json'}, json={'lat':lat, 'lng':lng})
        self.json = req.json()
        self.forecasts = self.json['properties']['periods']
        return self.json