From 2613906e2c43090deb564d1b72674a6238fefdf6 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Mon, 22 Jul 2019 21:07:59 +0530 Subject: [PATCH] Change content type --- server.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index dfb5fb5..85c04a8 100644 --- a/server.py +++ b/server.py @@ -157,7 +157,10 @@ def index(): def main(location, geocoder, cache_db, kind, unit): - coordinates = get_coordinates(location, geocoder, cache_db) + try: + coordinates = get_coordinates(location, geocoder, cache_db) + except KeyError: + return "Location Not found" weather = get_weather(coordinates) text = weather_to_text(weather, kind, unit, coordinates[2]) return ("\n" + text + "\n\n" + config.source + "\nPowered by Dark Sky - " @@ -209,3 +212,9 @@ app.add_url_rule('/p/f//', 'plain_location_f/', lambda location: app.add_url_rule('/p/f//t', 'plain_today_location_f', lambda location: strip_colors(main(location, geocoder, cache_db, "hourly", "f"))) + + +@app.after_request +def after(response): + response.headers['Content-Type'] = "text/plain; charset=utf-8" + return response