-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.py
45 lines (34 loc) · 1.02 KB
/
weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# weather.py
import argparse
from configparser import ConfigParser
def read_user_cli_args():
"""Handles the cli user interaction
Returns
argparse.namespace: populated namespace object
"""
parser = argparse.ArgumentParser(
description="gets weather and temp information for a city"
)
parser.add_argument(
"city", nargs="+", type=str, help="enter the city name"
)
parser.add_argument(
"-i",
"--imperial",
action="store_true",
help="display the temperature in imperial units",
)
return parser.parse_args()
# ...
if __name__ == "__main__":
user_args = read_user_cli_args()
print(user_args.city, user_args.imperial)
def _get_api_key():
""" Fetch api key from config file.
Expects a config file named secrets.ini with structure
[openweather]
api_key=<my-openweather-api-key>
"""
config = ConfigParser()
config.read("secrets.ini")
return config["openweather"]["api_key"]