Created
January 20, 2021 17:14
-
-
Save crides/46e4016a1a8a70b25663fd82e12d65ac to your computer and use it in GitHub Desktop.
A simple script to check the Webboard for ECE445 for new posts and replies to all posts, using the cookie provided by the user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import requests | |
| from bs4 import BeautifulSoup | |
| import time | |
| PACE_URL = "https://courses.engr.illinois.edu/ece445/pace/" | |
| BOARD_URL = PACE_URL + "web-board.asp" | |
| old_replies = {} | |
| while True: | |
| resp = requests.get(BOARD_URL, headers={"cookie": "ASPSESSIONIDAWBRRRQR=$COOKIE"}) | |
| soup = BeautifulSoup(resp.content, 'html.parser') | |
| rows = soup.select("div#content table tbody tr") | |
| data = {} | |
| for row in rows: | |
| children = [t for t in row.children if t.name] | |
| title = [t for t in children[1].children if t.name] | |
| datum = { | |
| "replies": int(children[3].text), | |
| "read": bool(children[0].children), | |
| "type": children[2].text, | |
| "id": int(title[0].attrs["href"].split("=")[1]), | |
| "link": PACE_URL + title[0].attrs["href"], | |
| "author": title[1].text, | |
| "title": title[0].text, | |
| } | |
| data[datum["id"]] = datum | |
| replies = {d["id"]: d["replies"] for d in data.values()} | |
| for reply in replies.items(): | |
| detail = data[reply[0]] | |
| if not detail["read"]: | |
| if reply[0] in old_replies: | |
| diff = reply[1] - old_replies[reply[0]] | |
| if diff > 0: | |
| print(f"{diff} new replies for thread \"{detail['title']}\"") | |
| print("") | |
| else: | |
| print(f"New thread:") | |
| print(f"\"{detail['title']}\" {detail['link']}") | |
| print(detail['author']) | |
| print("") | |
| old_replies = replies | |
| time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment