Skip to content

Instantly share code, notes, and snippets.

@micolous
Created September 5, 2012 09:18
Show Gist options
  • Save micolous/3633928 to your computer and use it in GitHub Desktop.
Save micolous/3633928 to your computer and use it in GitHub Desktop.
Conroy logic generator (ca. 2010)
#!/usr/bin/python2.4
# please share your additions with me: http://micolous.id.au/contact-me
verbs = ['hate','translocate','watch','like','shake','attack','eat','engineer','wrestle','throw','evaporate','think about','discover','buy','consult','roast','boil','enjoy','critique','call','photograph','play with','contact','sing with','discuss','thrill','hack','forecast','replace guns with','issue','recieve','refuse to sponsor','conspire with','conspire against','purchase computers from','play football with','talk to','clean','spread rumours about','fine','damage','troll','vote for','lose','offer','compensate','irrigate','pave','are not','are','make forum posts about','have']
nouns = ['plumbers','bicycles','balls','corn','peas','beetroot','clocks','chairs','cameras','unicorns','children','pirates','hands','songs','trucks','senators','digital television','laptops','sausages','foghorns','telstra','barbarians','ewoks','the nbn','dr. tran','books','walkie-talkies','black stars','francis wheat','mplayer','valhalla','reloaded','triads','the illuminati','terrorists','the ghost of billy mays','pop stars','big brother','triquarters','corey doctorow\'s blimp','pokemon','forums','the rules','the game','the streetgeek hate machine','the wheel of win','the randomiser','free beer','the contest','minorities','politicians','a microkernel architecture']
font_file = 'Arial_Bold.ttf'
from PIL import Image, ImageFont, ImageDraw
from random import randint
from sys import exit #, argv
from os import remove, environ
from tempfile import mktemp
argv = environ['PATH_INFO'].split('/')
def rand_entry(arr):
return arr[randint(0,len(arr)-1)]
def error(txt):
print """Content-type: text/plain
Error: %s""" % (txt,)
exit()
def args_help():
print """Content-type: text/plain
This script generates random false quotes of Senator Conroy.
There are currently %s verbs and %s nouns in the list, making a total of
%s possible quotes.
How to use:
conroy.py/0_0_0_255-255_255_255_255-14.png
Where:
0_0_0_255 == background colour (red _ green _ blue _ alpha, 0 = minimum, 255 = maximum)
255_255_255_255 = foreground colour
14 == font size (must be 6 - 40)
If you see this you're doing it wrong.
Text mode (for testing):
conroy.py/t
This script was inspired by http://conroylogic.com/
Source code is available:
conroy.py/s
""" % (len(verbs), len(nouns), len(verbs)*len(nouns),)
exit()
# /me giggles
# (there was a forum post here that had every post state "but why to wait for next year or maybe you could drop that idea by that time", and I used this script as my forum .signature)
if environ.has_key('HTTP_REFERER') and 'streetgeek.com.au/portal/modules.php?name=Forums&file=viewtopic&t=3483' in environ['HTTP_REFERER']:
txt = '"but why to wait for next year or maybe you could drop that idea by that time"'
else:
txt = '"if you %s %s, then you must hate children"' % (rand_entry(verbs), rand_entry(nouns))
if len(argv) > 1 and argv[1].lower() == "t":
print """Content-type: text/plain
""" + txt
elif len(argv) > 1 and argv[1].lower() == "s":
print """Content-type: text/plain
""" + open(environ['SCRIPT_FILENAME'],'r').read()
else:
bg = (0, 0, 0, 255)
fg = (255, 255, 255, 255)
size = 16
if len(argv) > 1:
args = argv[1].split("-")
if len(args) != 3: args_help()
args[2] = args[2].split(".")[0]
bg = args[0].split("_")
fg = args[1].split("_")
if len(bg) != 4 or len(fg) != 4: args_help()
try:
bg = (int(bg[0]), int(bg[1]), int(bg[2]), int(bg[3]))
fg = (int(fg[0]), int(fg[1]), int(fg[2]), int(fg[3]))
size = int(args[2])
except:
args_help()
for b in bg:
if b > 255 or b < 0: args_help()
for b in fg:
if b > 255 or b < 0: args_help()
if size > 40 or size < 6: args_help()
try:
font = ImageFont.truetype(font_file, size)
except:
error("Missing font file")
tmp = mktemp(".png")
image = Image.new("RGBA", font.getsize(txt), bg)
draw = ImageDraw.Draw(image)
draw.text((0, 0), txt, fill=fg, font=font)
image.save(tmp, "PNG")
del image, draw, txt, font
fh = open(tmp, "rb")
print """Content-Type: image/png
""" + fh.read()
fh.close()
remove(tmp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment