Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions examples/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ def __init__(self, address):
self.address = geolocator.geocode(address)
print(geolocator.geocode(address).raw)

def city(self):
return self.address.address.split(',')[0].strip()

def town(self):
return self.address.address.split(',')[3].strip()

def region(self):
return self.address.address.split(',')[4].strip()

def country(self):
return self.address.address.split(',')[-1].strip()

def city(self):
return self.address.address.split(',')[0].strip()

def continent(self):
return self.address.address.split(',')[-2].strip()
def district(self):
if self.address.address.split(',')[1].strip().count(' ') > 1:
return self.address.address.split(',')[2].strip()
Expand Down
37 changes: 24 additions & 13 deletions examples/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@

class Weather():
def __init__(self):
self.location = get_city_id(input('Enter the city you want know the weather (Lviv, UA): \n'))
inp = input('Enter the city you want know the weather (Lviv, UA): \n')
try:
inp = inp.split(',')
if len(inp[0]) > 2:
print("Incorrect country code")
if len(inp[1]) > 10:
print("Incorrect city name")
except IndexError as e:
print(e)
self.location = get_city_id(inp)

def get_daily_weather_in_location(self):
url = get_daily_url(self.location)
Expand All @@ -22,26 +31,29 @@ def get_weekly_weather_in_location(self):
jdata = json.loads(output)
path.close()
return jdata

def get_monthly_weather_in_location(self):
url = get_monthly_url(self.location)
path = urllib.request.urlopen(url)
output = path.read().decode('utf-8')
jdata = json.loads(output)
path.close()
return jdata

def temperature(self, data):
temp = data['main']
return temp['temp']
return data['main']['temp']

def wind_speed(self, data):
temp = data['wind']
return temp['speed']
return data['wind']['speed']

def humidity(self, data):
temp = data['main']
return temp['humidity']
return data['main']['humidity']

def pressure(self, data):
temp = data['main']
return temp['pressure']
return data['main']['pressure']

def status(self, data):
temp = data['weather']
return temp['main']
return data['weather']['main']

def wind_vector(self, data):
temp = data['wind']
Expand All @@ -55,8 +67,7 @@ def wind_vector(self, data):
return 'East'

def visibility(self, data):
temp = data['id']
return temp['visibility']
return data['id']['visibility']

def daily_forecast(self, data):
tim = time.time()
Expand Down