Skip to content

Commit

Permalink
Merge pull request #24 from bonswouar/raw-message
Browse files Browse the repository at this point in the history
Add --raw option to retrieve the full html message
  • Loading branch information
kannibalox authored Oct 28, 2023
2 parents 1787e76 + ab311cf commit 8fb5d6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/ptpapi/scripts/ptp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/ptpapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
Expand Down

0 comments on commit 8fb5d6b

Please sign in to comment.