2019-08-27 16:38:38 +02:00
|
|
|
#!/usr/local/bin/python3.7
|
2020-12-29 06:03:07 +01:00
|
|
|
r"""
|
2019-08-27 16:38:38 +02:00
|
|
|
CGI script that requests user supplied text using the INPUT status, and
|
|
|
|
pipes it into the `cowsay` program.
|
|
|
|
|
|
|
|
_________________
|
|
|
|
< Gemini is cool! >
|
|
|
|
-----------------
|
|
|
|
\ ^__^
|
|
|
|
\ (oo)\_______
|
|
|
|
(__)\ )\/\
|
|
|
|
||----w |
|
|
|
|
|| ||
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
query = os.environ["QUERY_STRING"]
|
|
|
|
if not query:
|
2019-08-28 04:52:38 +02:00
|
|
|
print("10 Enter your cowsay message: ")
|
2019-08-27 16:38:38 +02:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
text = urllib.parse.unquote(query)
|
|
|
|
try:
|
|
|
|
proc = subprocess.run(
|
|
|
|
["/usr/local/bin/cowsay"],
|
|
|
|
input=text,
|
|
|
|
capture_output=True,
|
|
|
|
check=True,
|
|
|
|
text=True,
|
|
|
|
)
|
|
|
|
except:
|
|
|
|
print("42 Unexpected Error")
|
|
|
|
else:
|
|
|
|
print("20 text/plain")
|
|
|
|
print(proc.stdout)
|