Last active
April 9, 2020 05:02
-
-
Save MineRobber9000/803840e86f386d438608eb85920b6a6a to your computer and use it in GitHub Desktop.
uwu-ified wikipedia https://khuxkm.nand.sh/uwupedia.cgi
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 cgi, wikipedia, os, sys, traceback, wikipedia.exceptions | |
from urllib import parse | |
wikipedia.USER_AGENT = "uwupedia (https://gist.github.com/MineRobber9000/803840e86f386d438608eb85920b6a6a)" | |
# inline uwu | |
SUBSTITUTES = dict( | |
l="w", | |
r="w", | |
L="W", | |
R="W" | |
) | |
def translate(s,th_to_f=False): | |
out = "" | |
for i, c in enumerate(s): | |
if c in SUBSTITUTES: | |
out+=SUBSTITUTES[c] | |
else: | |
if c=="t": # special case it | |
if s[i-1]=="t": | |
continue | |
elif s[i+1]=="t": # tt => dd | |
out+="dd" | |
elif th_to_f and s[i+1]=="h": # th => f | |
out+="f" | |
else: out+=c | |
elif th_to_f and c=="h" and s[i-1]=="t": continue | |
elif c=="o" and s[i-1] in "mn": out+="yo" | |
else: out+=c | |
return out | |
# end inline uwu | |
print("Content-Type: text/plain; charset=utf-8") | |
print() | |
query = os.environ["QUERY_STRING"] | |
if not query: | |
print("To uwu-ify a wikipedia page:") | |
print("https://khuxkm.nand.sh/uwupedia.cgi?page=<title, url-encoded>") | |
sys.exit(0) | |
else: | |
query = parse.parse_qs(query) | |
try: | |
page = query.get("page")[0] | |
except: | |
print("To uwu-ify a wikipedia page:") | |
print("https://khuxkm.nand.sh/uwupedia.cgi?page=<title, url-encoded>") | |
sys.exit(0) | |
try: | |
page = wikipedia.page(page).content | |
except wikipedia.exceptions.DisambiguationError as e: | |
print(f"{page} may refer to:") | |
for alt in e.options: | |
print(f" - {alt}") | |
sys.exit(0) | |
except: | |
print("An error occurred:") | |
for line in traceback.format_exception_only(*sys.exc_info()[:2]): | |
print(line.strip()) | |
sys.exit(0) | |
print(translate(page)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment