|
1 | 1 | from argparse import ArgumentParser
|
| 2 | +from configparser import ConfigParser |
2 | 3 |
|
3 | 4 | import requests
|
4 | 5 | from requests.auth import HTTPBasicAuth
|
5 | 6 |
|
6 | 7 | parser = ArgumentParser()
|
7 |
| -parser.add_argument("host", help="The host to connect to") |
8 |
| -parser.add_argument("username", help="The username for the user") |
9 |
| -parser.add_argument("password", help="The password for the user") |
| 8 | +parser.add_argument("--host", default=None, help="The host to connect to") |
| 9 | +parser.add_argument("--username", default=None, help="The username for the user") |
| 10 | +parser.add_argument("--password", default=None, help="The password for the user") |
10 | 11 | args = parser.parse_args()
|
11 | 12 |
|
12 |
| -host = args.host |
13 |
| -username = args.username |
14 |
| -password = args.password |
| 13 | +config = ConfigParser() |
| 14 | +config.read("config.ini") |
| 15 | +host = config["DEFAULT"]["host"] |
| 16 | +username = config["DEFAULT"]["username"] |
| 17 | +password = config["DEFAULT"]["password"] |
| 18 | + |
| 19 | +host = args.host if args.host else host |
| 20 | +username = args.username if args.username else username |
| 21 | +password = args.password if args.password else password |
15 | 22 |
|
16 | 23 | response = requests.get(
|
17 |
| - f"https://{host}/api/v1/data", |
18 |
| - auth=HTTPBasicAuth(username, password) |
| 24 | + f"https://{host}/api/v1/data", auth=HTTPBasicAuth(username, password) |
19 | 25 | )
|
20 | 26 | mydata = response.json()["the-data-i-want"]
|
21 | 27 |
|
|
0 commit comments