-
-
Save chilismaug/0a8af443fc42fbe4228c2c1e6bbda20c to your computer and use it in GitHub Desktop.
Simple flask-restful GET json stub with a "current weather" OpenWeather response doc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask_restful import Resource, Api | |
app = Flask(__name__) | |
api = Api(app) | |
class SimpleRest(Resource): | |
def get(self): | |
return { | |
'weather': [ | |
{ | |
'id': 800, | |
'main': 'Clear', | |
'description': 'clear sky', | |
'icon': '01d' | |
} | |
], | |
'coord': { | |
'lon': -122.08, | |
'lat': 37.39 | |
}, | |
'base': 'stations', | |
'main': { | |
'temp': 282.55, | |
'feels_like': 281.86, | |
'temp_min': 280.37, | |
'temp_max': 284.26, | |
'pressure': 1023, | |
'humidity': 100 | |
}, | |
'visibility': 16093, | |
'wind': { | |
'speed': 1.5, | |
'deg': 350 | |
}, | |
'clouds': { | |
'all': 1 | |
}, | |
'dt': 1560350645, | |
'sys': { | |
'type': 1, | |
'id': 5122, | |
'message': 0.0139, | |
'country': 'US', | |
'sunrise': 1560343627, | |
'sunset': 1560396563 | |
}, | |
'timezone': -25200, | |
'id': 420006353, | |
'name': 'Xanadu', | |
'cod': 200 | |
} | |
api.add_resource(SimpleRest, '/') | |
if __name__ == '__main__': | |
app.run(port=8001, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's how I use it in my Flask weather app - the "data" variable gets the stub weather when it's running in local dev mode