-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsg_parser.py
22 lines (20 loc) · 878 Bytes
/
msg_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class GiveawayMessage:
def __init__(self):
self.platform = None
self.title = None
self.description = None
self.price = None
self.image = None
self.link = None
def parse_template(template: str, msg: GiveawayMessage) -> str:
with open(template, "r", encoding="utf-8") as f:
content = f.read()
return content \
.replace("{BOLDON}", "<b>") \
.replace("{BOLDOFF}", "</b>") \
.replace("{SOURCE}", str(msg.platform)) \
.replace("{TITLE}", str(msg.title)) \
.replace("{DESCRIPTION}", str(msg.description)) \
.replace("{PRICE}", str(msg.price)) \
.replace("{LINK}", "<a href='" + str(msg.link) + "'> " + str(msg.link) + "</a>" if msg.link is not None else "") \
.replace("{IMAGE}", "<img src='" + str(msg.image) + "'>" if msg.image is not None else "")