diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-05-25 19:24:43 +0200 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-05-25 19:24:43 +0200 |
| commit | cc84a7857c120d4c1c1b150e7fb8676d30fb5957 (patch) | |
| tree | 6a7d15f7e757cbd2b358661415311c9ef6f901d6 /mailinglist/launchpad.py | |
| parent | 4a7460d3f95c454544e9ecea8d4ff129b0b48885 (diff) | |
| download | emulator-bug-study-cc84a7857c120d4c1c1b150e7fb8676d30fb5957.tar.gz emulator-bug-study-cc84a7857c120d4c1c1b150e7fb8676d30fb5957.zip | |
refactor mailinglist script
Diffstat (limited to 'mailinglist/launchpad.py')
| -rwxr-xr-x | mailinglist/launchpad.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/mailinglist/launchpad.py b/mailinglist/launchpad.py index 6b1cdd1e..cb37996c 100755 --- a/mailinglist/launchpad.py +++ b/mailinglist/launchpad.py @@ -1,27 +1,34 @@ -from requests import get +from requests import get, Response from os import makedirs, path -def process_launchpad_bug(bug_id) -> bool: - if path.exists(f"output_launchpad/{bug_id}"): - return False +def launchpad_id_valid(bug_id : str) -> bool: + return len(bug_id) == 7 or len(bug_id) == 6 - bug_url = f"https://api.launchpad.net/1.0/bugs/{bug_id}" +def response_valid(response : Response) -> bool: + return 'application/json' in response.headers.get('Content-Type', '') - bug_response = get(url = bug_url) +def process_launchpad_bug(bug_id : str) -> None: + if not launchpad_id_valid(bug_id): + print(f"{bug_id} is not valid") + return - if not 'application/json' in bug_response.headers.get('Content-Type', ''): - return False + if path.exists(f"output_launchpad/{bug_id}"): + print(f"output_launchpad/{bug_id} exists already") + return - bug_data = bug_response.json() + bug_url = f"https://api.launchpad.net/1.0/bugs/{bug_id}" + bug_response = get(bug_url) - messages_response = get(url = bug_data['messages_collection_link']) + if not response_valid(bug_response): + print(f"Response for {bug_id} is not valid") + return + bug_data = bug_response.json() + messages_response = get(bug_data['messages_collection_link']) messages_data = messages_response.json() - makedirs("output_launchpad", exist_ok=True) + makedirs("output_launchpad", exist_ok = True) with open(f"output_launchpad/{bug_id}", "w") as file: file.write(f"{bug_data['title']}\n\n") - for entry in messages_data['entries']: file.write(f"{entry['content']}\n\n") - return True |