mirror of https://gitlab.com/ceda_ei/sky
Complete get_coordinates. Add logic. Add schema.
This commit is contained in:
parent
c3bd238bdc
commit
efce2ccd2e
|
@ -3,3 +3,7 @@ mapbox_key = "pk.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
|||
|
||||
# Access token for Dark Sky
|
||||
dark_sky_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
|
||||
# Source line. Will be attached to the end of every message
|
||||
# This line is necessary for complying with AGPL.
|
||||
source = "Source: https://gitlab.com/ceda_ei/sky\n"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
CREATE TABLE IF NOT EXISTS location(name varchar(255) PRIMARY KEY, lat real, lon real);
|
30
server.py
30
server.py
|
@ -10,16 +10,40 @@ app = Flask(__name__)
|
|||
cache_db = sqlite3.connect("cache.sqlite")
|
||||
|
||||
|
||||
def get_coordinates(location, geocoder, cache_db):
|
||||
row = cache_db.execute("select lat,lon from location where name = ?;",
|
||||
(location,)).fetchone()
|
||||
|
||||
if row is not None:
|
||||
return (row[0], row[1])
|
||||
|
||||
loc = geocoder.forward(location)
|
||||
coordinates = loc.geojson()['features'][0]['center']
|
||||
cache_db.execute("insert into location(name, lat, lon) values(?,?,?)",
|
||||
(location, *coordinates))
|
||||
return tuple(coordinates)
|
||||
|
||||
|
||||
def get_weather(coordinates):
|
||||
return coordinates
|
||||
|
||||
|
||||
def weather_to_text(text):
|
||||
return str(text)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
text = ("To get the weather for a location, run curl "
|
||||
"https://sky.webionite.com/location. \n"
|
||||
"Source: https://gitlab.com/ceda_ei/sky\n")
|
||||
"https://sky.webionite.com/location. \n" + config.source)
|
||||
return text
|
||||
|
||||
|
||||
def main(location, geocoder, cache_db):
|
||||
return
|
||||
coordinates = get_coordinates(location, geocoder, cache_db)
|
||||
weather = get_weather(coordinates)
|
||||
text = weather_to_text(weather)
|
||||
return text + "\n" + config.source
|
||||
|
||||
|
||||
app.add_url_rule('/<location>', 'location', lambda location:
|
||||
|
|
Loading…
Reference in New Issue