-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_dict.py
More file actions
49 lines (39 loc) · 1.17 KB
/
Copy pathuser_dict.py
File metadata and controls
49 lines (39 loc) · 1.17 KB
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
45
46
47
48
49
import requests
import logging
import os
import urllib3
urllib3.disable_warnings()
HTTP_PARSE_LOG = "employees.log"
HTTP_PARSE_OUT = "employees.out"
def clear_obsolete(file_out: str, file_log: str) -> None:
try:
os.remove(file_out)
os.remove(file_log)
except OSError as e:
print("Error: %s - %s." % (e.filename, e.strerror))
def get_user_email(name: str) -> None:
url_path = f"https://localhost/api/users/{name}?user=andy"
logging.info(f"Sending to: {url_path}")
r = requests.get(
url_path,
auth=("andy", "pass"),
verify=False,
)
logging.info(r.status_code)
with open(HTTP_PARSE_OUT, "a") as f:
try:
f.write(r.json()["email"] + "\n")
except KeyError as e:
logging.error(f"No user within DB")
def main() -> None:
clear_obsolete(HTTP_PARSE_LOG, HTTP_PARSE_OUT)
logging.basicConfig(
level=logging.INFO,
handlers=[logging.FileHandler(HTTP_PARSE_LOG), logging.StreamHandler()],
)
while True:
logging.info("Kindly input username: ")
username = input()
get_user_email(username)
if __name__ == "__main__":
main()