From 5ff211c1dba59ff3eb2d8a1cda1fff9eaa2ccce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Cort=C3=A9s?= Date: Thu, 19 Nov 2020 02:47:55 -0300 Subject: [PATCH] Primer commit con datos --- __init__.py | 0 app.py | 22 ++++++++++++++++++++++ services/__init__.py | 4 ++++ services/currency.py | 12 ++++++++++++ services/photos.py | 12 ++++++++++++ services/weather.py | 13 +++++++++++++ settings.py.example | 4 ++++ 7 files changed, 67 insertions(+) create mode 100644 __init__.py create mode 100644 app.py create mode 100644 services/__init__.py create mode 100644 services/currency.py create mode 100644 services/photos.py create mode 100644 services/weather.py create mode 100644 settings.py.example diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/app.py new file mode 100644 index 0000000..39594f8 --- /dev/null +++ b/app.py @@ -0,0 +1,22 @@ +from flask import Flask +from start import services + +app = Flask(__name__) +app.config.from_object('start.settings') + +@app.route('/currency') +def currency(): + return services.currency.get(app.config['FOREX_KEY']) + +@app.route('/weather') +def weather(): + return services.weather.get('temuco', app.config['OPENWEATHERMAP_KEY']) + +@app.route('/photos') +def photos(): + return services.photos.get(app.config['UNSPLASH_KEY']) + + +@app.route('/') +def hello_world(): + return 'Hello, World!' diff --git a/services/__init__.py b/services/__init__.py new file mode 100644 index 0000000..50f8c7b --- /dev/null +++ b/services/__init__.py @@ -0,0 +1,4 @@ +from . import weather +from . import currency +from . import photos + diff --git a/services/currency.py b/services/currency.py new file mode 100644 index 0000000..ec1080e --- /dev/null +++ b/services/currency.py @@ -0,0 +1,12 @@ +import requests + +url = "https://v2.api.forex/rates/latest.json" + +def get(key): + data = { + 'key': key, + } + + response = requests.get(url, params=data) + return response.json() + diff --git a/services/photos.py b/services/photos.py new file mode 100644 index 0000000..7fa8abb --- /dev/null +++ b/services/photos.py @@ -0,0 +1,12 @@ +import requests + +url = "https://api.unsplash.com/photos/" + +def get(key): + data = { + 'client_id': key, + } + + response = requests.get(url, params=data) + return {'result': response.json()} + diff --git a/services/weather.py b/services/weather.py new file mode 100644 index 0000000..79adbcb --- /dev/null +++ b/services/weather.py @@ -0,0 +1,13 @@ +import requests + +url = "https://api.openweathermap.org/data/2.5/weather/" + +def get(city, key): + data = { + 'q': city, + 'appid': key, + 'units': 'metric', + } + response = requests.get(url, params=data) + return response.json() + diff --git a/settings.py.example b/settings.py.example new file mode 100644 index 0000000..5569a05 --- /dev/null +++ b/settings.py.example @@ -0,0 +1,4 @@ +DEBUG=True +FOREX_KEY='SECRET' +UNSPLASH_KEY='SECRET' +OPENWEATHERMAP_KEY='SECRET'