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",
|
"username": "testuser",
|
||||||
"password": "testpassword",
|
"password": "testpassword",
|
||||||
"webhook": "https://discord.com/webhook/abc/def"
|
"webhook": "https://discord.com/webhook/abc/def",
|
||||||
|
"logout": false
|
||||||
}
|
}
|
19
main.py
19
main.py
@ -12,6 +12,7 @@ with open("config.json", "r") as fp:
|
|||||||
USERNAME = config["username"]
|
USERNAME = config["username"]
|
||||||
PASSWORD = config["password"]
|
PASSWORD = config["password"]
|
||||||
WEBHOOK_URL = config["webhook"]
|
WEBHOOK_URL = config["webhook"]
|
||||||
|
LOGOUT = config["logout"]
|
||||||
|
|
||||||
|
|
||||||
def loop():
|
def loop():
|
||||||
@ -30,11 +31,13 @@ def loop():
|
|||||||
|
|
||||||
# Get new posts
|
# Get new posts
|
||||||
print("Getting new posts...")
|
print("Getting new posts...")
|
||||||
|
has_newposts = False
|
||||||
newposts_resp = br.open(newposts_url)
|
newposts_resp = br.open(newposts_url)
|
||||||
newposts_html = newposts_resp.get_data()
|
newposts_html = newposts_resp.get_data()
|
||||||
bs = BeautifulSoup(newposts_html, features="html5lib")
|
bs = BeautifulSoup(newposts_html, features="html5lib")
|
||||||
all_newposts = bs.find_all("dl", attrs={"class": "topic_unread"})
|
all_newposts = bs.find_all("dl", attrs={"class": "topic_unread"})
|
||||||
for newpost in all_newposts:
|
for newpost in all_newposts:
|
||||||
|
has_newposts = True
|
||||||
newpost_title = newpost.find(class_="topictitle").contents[0]
|
newpost_title = newpost.find(class_="topictitle").contents[0]
|
||||||
newpost_link = newpost.find(class_="topictitle")["href"]
|
newpost_link = newpost.find(class_="topictitle")["href"]
|
||||||
newpost_username = newpost.find(class_="username").contents[0]
|
newpost_username = newpost.find(class_="username").contents[0]
|
||||||
@ -60,15 +63,17 @@ def loop():
|
|||||||
}
|
}
|
||||||
requests.post(WEBHOOK_URL, json=webhook_data)
|
requests.post(WEBHOOK_URL, json=webhook_data)
|
||||||
|
|
||||||
# Mark all read
|
if has_newposts:
|
||||||
print("Mark all read...")
|
# Mark all read
|
||||||
a = bs.find("a", class_="mark-read")
|
print("Mark all read...")
|
||||||
mark_read_url = a["href"]
|
a = bs.find("a", class_="mark-read")
|
||||||
br.open(mark_read_url)
|
mark_read_url = a["href"]
|
||||||
|
br.open(mark_read_url)
|
||||||
|
|
||||||
# Logout
|
# Logout
|
||||||
print("Logout...")
|
if LOGOUT:
|
||||||
br.open(logout_url)
|
print("Logout...")
|
||||||
|
br.open(logout_url)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user