I am writing a module. how to get json not for each parameter separately. and on all request entirely?
for example, I request temperature and humidity. json is requested 2 times than it consumes a limit of calls to api and slows down the work
import urllib.request, json import datetime def time_converter(time): converted_time = datetime.datetime.fromtimestamp( int(time) ).strftime('%H:%M') return converted_time def geturl(city): #Moscow urll = 'http://api.openweathermap.org/data/2.5/weather?q=' + city +',ru&mode=json&units=metric&lang=ru&appid=*******' with urllib.request.urlopen(urll) as url: data = json.loads(url.read().decode()) return data #print(data) def temp(city): temp = str(geturl(city)['main']['temp'])+'\xb0' + 'C'+'\n' return temp def pressure(city): pressure = str(geturl(city)['main']['pressure'])+' ммРтСт'+'\n' return pressure def humidity(city): humidity = str(geturl(city)['main']['humidity'])+'%'+'\n' return humidity def temp_min(city): temp_min = str(geturl(city)['main']['temp_min'])+'\xb0' + 'C'+'\n' return temp_min def temp_max(city): temp_max = str(geturl(city)['main']['temp_max'])+'\xb0' + 'C'+'\n' return temp_max def visibility(city): visibility = str(geturl(city)['visibility'])+'метров'+'\n' return visibility def wind(city): wind= str(geturl(city)['wind']['speed'])+'м/с'+'\n' return wind def weather(city): weather = str(geturl(city)['weather'][0]['description']) + '\n' return weather def sunrise(city): sunrise = str(time_converter(geturl(city)['sys']['sunrise'])) + '\n' return sunrise def sunset(city): sunset = str(time_converter(geturl(city)['sys']['sunset'])) + '\n' return sunset
geturl(city)everywhere, then make a general method of getting information. And from the information you pull out separately for all data: wind, weather, visibility, etc. Then the request will be one. - gil9red