https://github.com/chand1012/weather-api-worker
Middleware for https://api.weather.gov/
https://github.com/chand1012/weather-api-worker
cloudflare-workers javascript nodejs webpack
Last synced: 2 months ago
JSON representation
Middleware for https://api.weather.gov/
- Host: GitHub
- URL: https://github.com/chand1012/weather-api-worker
- Owner: chand1012
- License: mit
- Created: 2020-05-09T02:25:30.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T10:56:59.000Z (about 3 years ago)
- Last Synced: 2025-01-31T12:12:09.704Z (over 1 year ago)
- Topics: cloudflare-workers, javascript, nodejs, webpack
- Language: JavaScript
- Homepage: https://weather.chand1012.workers.dev/
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Weather Worker
This was a simple project meant for me to teach myself how to use a serverless system, in this case [Cloudflare Workers](https://workers.cloudflare.com/). 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:
```Python
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})
print(req.json())
```
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](https://github.com/chand1012/discord-weather-bot):
```Python
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
```