Acomodados packages para funcionar con gunicorn
This commit is contained in:
0
home/__init__.py
Normal file
0
home/__init__.py
Normal file
21
home/entry.py
Normal file
21
home/entry.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from flask import Flask
|
||||
from . import services
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object('home.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!'
|
||||
1
home/services/__init__.py
Normal file
1
home/services/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import currency, photos, weather
|
||||
12
home/services/currency.py
Normal file
12
home/services/currency.py
Normal file
@@ -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()
|
||||
|
||||
12
home/services/photos.py
Normal file
12
home/services/photos.py
Normal file
@@ -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()}
|
||||
|
||||
13
home/services/weather.py
Normal file
13
home/services/weather.py
Normal file
@@ -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()
|
||||
|
||||
4
home/settings.py.example
Normal file
4
home/settings.py.example
Normal file
@@ -0,0 +1,4 @@
|
||||
DEBUG=True
|
||||
FOREX_KEY='SECRET'
|
||||
UNSPLASH_KEY='SECRET'
|
||||
OPENWEATHERMAP_KEY='SECRET'
|
||||
Reference in New Issue
Block a user