don't mark new posts if no posts, option for logout

This commit is contained in:
Amazed 2020-06-10 19:51:19 +02:00
parent 7918debc20
commit 50597fffef
2 changed files with 14 additions and 8 deletions

View File

@ -1,5 +1,6 @@
{
"username": "testuser",
"password": "testpassword",
"webhook": "https://discord.com/webhook/abc/def"
"webhook": "https://discord.com/webhook/abc/def",
"logout": false
}

19
main.py
View File

@ -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,15 +63,17 @@ def loop():
}
requests.post(WEBHOOK_URL, json=webhook_data)
# Mark all read
print("Mark all read...")
a = bs.find("a", class_="mark-read")
mark_read_url = a["href"]
br.open(mark_read_url)
if has_newposts:
# Mark all read
print("Mark all read...")
a = bs.find("a", class_="mark-read")
mark_read_url = a["href"]
br.open(mark_read_url)
# Logout
print("Logout...")
br.open(logout_url)
if LOGOUT:
print("Logout...")
br.open(logout_url)
if __name__ == "__main__":