Created
October 22, 2020 22:06
-
-
Save pedrohsbarbosa99/f7461fea63ac74d7c0e94fc9d864546d to your computer and use it in GitHub Desktop.
This file contains 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 django.conf import settings | |
import requests | |
def get_cd_city(): | |
token = settings.API_TOKEN | |
r = requests.get('https://api.hgbrasil.com/geoip?key={}&address=remote&precision=false'.format(token)) | |
data = r.json() | |
dados_list = data['results']['woeid'] | |
return dados_list | |
def get_tempo(): | |
token = settings.API_TOKEN | |
cod_city = get_cd_city() | |
r = requests.get('https://api.hgbrasil.com/weather?format=json-cors&key={}&woeid={}'.format(token, cod_city)) | |
data = r.json() | |
dados_list = data['results'] | |
return dados_list | |
def next_days(): | |
token = settings.API_TOKEN | |
cod_city = get_cd_city() | |
r = requests.get('https://api.hgbrasil.com/weather?format=json-cors&key={}&woeid={}'.format(token, cod_city)) | |
data2 = r.json() | |
dados_list2 = data2['results'] | |
return dados_list2 |
This file contains 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 django.views.generic import TemplateView | |
from .services import get_tempo, next_days | |
class GetTempo(TemplateView): | |
template_name = 'tempo.html' | |
def get_context_data(self, *args, **kwargs): | |
context = { | |
'data' : get_tempo(), | |
'data1' : next_days(), | |
} | |
return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment