-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
04d25f1
commit 5ec7a07
Showing
1 changed file
with
12 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import geocoder | ||
import requests | ||
|
||
HTTP_STATUS_OK = 200 | ||
loc = geocoder.ip('me').json # Resolves location by IP | ||
city_country = f"{loc['city']},{loc['country']}" # City string for URL | ||
loc = geocoder.ip("me").json # Resolves location by IP | ||
city_country = f"{loc['city']},{loc['country']}" # City string for URL | ||
APPID = "beb97c1ce62559bba4e81e28de8be095" | ||
weather = requests.get(f"http://api.openweathermap.org/data/2.5/weather?APPID={APPID}&q={city_country}").json() | ||
weather = requests.get( | ||
f"http://api.openweathermap.org/data/2.5/weather?APPID={APPID}&q={city_country}" | ||
).json() | ||
if weather.get("cod") == HTTP_STATUS_OK: | ||
print(f"Weather in {city_country}\n------\n" + "\n".join(f"{key}: {value}" for key, value in weather.items())) | ||
else: print("Error fetching data.") | ||
print( | ||
f"Weather in {city_country}\n------\n" | ||
+ "\n".join(f"{key}: {value}" for key, value in weather.items()) | ||
) | ||
else: | ||
print("Error fetching data.") |