Skip to content

Instantly share code, notes, and snippets.

@Mothblocks
Last active September 20, 2021 04:43
Show Gist options
  • Save Mothblocks/203d698155b6b3803613b4f268417f69 to your computer and use it in GitHub Desktop.
Save Mothblocks/203d698155b6b3803613b4f268417f69 to your computer and use it in GitHub Desktop.
Automatically get trial admin threads
import re
import urllib.parse
import urllib.request
from bs4 import BeautifulSoup
from functools import reduce
request = urllib.request.Request("https://tgstation13.org/phpBB/viewforum.php?f=40", headers = {
"User-Agent": "Get Trial Threads Script",
})
board_with_trial_threads = urllib.request.urlopen(request)
soup = BeautifulSoup(board_with_trial_threads, "html.parser")
# Matches "Trialmin Review: Mothblocks", as well as "Trialmin Review 2.0: Mothblocks", which admins are known to do
trialmin_review_match = re.compile(r"Trialmin Review.*: (.+)$")
trial_threads = []
for topic in soup.find_all(class_="topictitle"):
if "This topic is locked" in topic.parent["title"]:
continue
title_match = trialmin_review_match.search(topic.string)
if title_match is None:
continue
url = reduce(urllib.parse.urljoin, ["https://tgstation13.org/phpBB/", topic["href"]])
trial_threads.append(f"<p>{title_match.group(1)}: <a href=\"{url}\">{url}</a></p>")
if len(trial_threads) > 0:
print("<p>The following Trial Review threads are open:</p>")
print("\n".join(trial_threads))
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
beautifulsoup4 = "*"
[requires]
python_version = "3.7"
{
"_meta": {
"hash": {
"sha256": "3835eeabe65e9d13177fdfe50cf32633d08ad7ec07974d195a76c37b2a4df8f1"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.7"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"beautifulsoup4": {
"hashes": [
"sha256:9a315ce70049920ea4572a4055bc4bd700c940521d36fc858205ad4fcde149bf",
"sha256:c23ad23c521d818955a4151a67d81580319d4bf548d3d49f4223ae041ff98891"
],
"index": "pypi",
"version": "==4.10.0"
},
"soupsieve": {
"hashes": [
"sha256:052774848f448cf19c7e959adf5566904d525f33a3f8b6ba6f6f8f26ec7de0cc",
"sha256:c2c1c2d44f158cdbddab7824a9af8c4f83c76b1e23e049479aa432feb6c4c23b"
],
"version": "==2.2.1"
}
},
"develop": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment