Skip to content

Commit 8f703bb

Browse files
authored
Merge pull request #9 from LairdStreak/main
Simple cmdline wttr consumer to view city weather
2 parents 002cebb + 0960a5d commit 8f703bb

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

wttr.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
::@name Get Weather for a city and display it in the console
3+
4+
::@description
5+
Takes input for city. Gives output of weather for a city in a text format.
6+
Command arg -c City
7+
::@/description
8+
9+
"""
10+
import argparse
11+
import requests
12+
13+
14+
PARSER = argparse.ArgumentParser()
15+
16+
PARSER.add_argument(
17+
"-c",
18+
"--city",
19+
dest="city",
20+
default="Christchurch",
21+
help="Name of the City to display weather info from wttr.in",
22+
)
23+
24+
25+
ARGS = PARSER.parse_args()
26+
27+
CITY = ARGS.city
28+
29+
30+
def get_weather():
31+
"""Display Weather for city in console"""
32+
url = f"https://wttr.in/{CITY}"
33+
response = requests.get(url=url, timeout=None)
34+
print(response.text)
35+
36+
37+
if __name__ == "__main__":
38+
get_weather()

0 commit comments

Comments
 (0)