Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --raw option to retrieve the full html message #24

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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