From ab311cfd70e3ebda3a9c196d452f8aba9db120a4 Mon Sep 17 00:00:00 2001 From: bonswouar Date: Sat, 28 Oct 2023 13:50:12 +0200 Subject: [PATCH] Add --raw option to retrieve the full html message --- src/ptpapi/scripts/ptp.py | 5 ++++- src/ptpapi/user.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ptpapi/scripts/ptp.py b/src/ptpapi/scripts/ptp.py index 5e96cef..2a73bb3 100755 --- a/src/ptpapi/scripts/ptp.py +++ b/src/ptpapi/scripts/ptp.py @@ -31,7 +31,7 @@ def do_inbox(api, args): user.inbox_conv(msg["ID"]) page += 1 elif args.conversation: - conv = user.inbox_conv(args.conversation) + conv = user.inbox_conv(args.conversation, args.raw) print(conv["Subject"]) for msg in conv["Message"]: print("{0} - {1}\n".format(msg["User"], msg["Time"])) @@ -514,6 +514,9 @@ def main(): inbox_parser.add_argument( "-p", "--page", help="Start at a certain page", type=int, default=1 ) + inbox_parser.add_argument( + "--raw", help="Combined with -c, fetch the raw HTML message", action="store_true", + ) inbox_parser.set_defaults(func=do_inbox) # Raw diff --git a/src/ptpapi/user.py b/src/ptpapi/user.py index 795539a..30957f1 100644 --- a/src/ptpapi/user.py +++ b/src/ptpapi/user.py @@ -178,7 +178,7 @@ def inbox(self, page=1): "Unread": bool("inbox-message--unread" in row["class"]), } - def inbox_conv(self, conv_id): + def inbox_conv(self, conv_id, raw=False): """Get a specific conversation from the inbox""" soup = bs4( session.base_get( @@ -189,7 +189,10 @@ def inbox_conv(self, conv_id): messages = [] for msg in soup.find_all("div", id=re.compile("^message"), class_="forum-post"): message = {} - message["Text"] = msg.find("div", class_="forum-post__body").text.strip() + if raw: + message["Text"] = msg.find("div", class_="forum-post__body") + else: + message["Text"] = msg.find("div", class_="forum-post__body").text.strip() username = msg.find("strong").find("a", class_="username") if username is None: message["User"] = "System"