don't mark new posts if no posts, option for logout
This commit is contained in:
parent
7918debc20
commit
50597fffef
@ -1,5 +1,6 @@
|
||||
{
|
||||
"username": "testuser",
|
||||
"password": "testpassword",
|
||||
"webhook": "https://discord.com/webhook/abc/def"
|
||||
"webhook": "https://discord.com/webhook/abc/def",
|
||||
"logout": false
|
||||
}
|
5
main.py
5
main.py
@ -12,6 +12,7 @@ with open("config.json", "r") as fp:
|
||||
USERNAME = config["username"]
|
||||
PASSWORD = config["password"]
|
||||
WEBHOOK_URL = config["webhook"]
|
||||
LOGOUT = config["logout"]
|
||||
|
||||
|
||||
def loop():
|
||||
@ -30,11 +31,13 @@ def loop():
|
||||
|
||||
# Get new posts
|
||||
print("Getting new posts...")
|
||||
has_newposts = False
|
||||
newposts_resp = br.open(newposts_url)
|
||||
newposts_html = newposts_resp.get_data()
|
||||
bs = BeautifulSoup(newposts_html, features="html5lib")
|
||||
all_newposts = bs.find_all("dl", attrs={"class": "topic_unread"})
|
||||
for newpost in all_newposts:
|
||||
has_newposts = True
|
||||
newpost_title = newpost.find(class_="topictitle").contents[0]
|
||||
newpost_link = newpost.find(class_="topictitle")["href"]
|
||||
newpost_username = newpost.find(class_="username").contents[0]
|
||||
@ -60,6 +63,7 @@ def loop():
|
||||
}
|
||||
requests.post(WEBHOOK_URL, json=webhook_data)
|
||||
|
||||
if has_newposts:
|
||||
# Mark all read
|
||||
print("Mark all read...")
|
||||
a = bs.find("a", class_="mark-read")
|
||||
@ -67,6 +71,7 @@ def loop():
|
||||
br.open(mark_read_url)
|
||||
|
||||
# Logout
|
||||
if LOGOUT:
|
||||
print("Logout...")
|
||||
br.open(logout_url)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user