Skip to content

Commit

Permalink
pull out teh memes and make em a module
Browse files Browse the repository at this point in the history
  • Loading branch information
rupa committed Jun 18, 2015
1 parent 97d607f commit 1de546c
Show file tree
Hide file tree
Showing 64 changed files with 428 additions and 1,976 deletions.
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
.DS_Store
*.pyc
html
src/jquery*.js
conversation.py
omg*.cgi
json.py
_tumblr
.old
dist
automeme.egg-info
62 changes: 0 additions & 62 deletions Makefile

This file was deleted.

23 changes: 23 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
A cheeky random nonsense generator.

Based on automeme by Liam Cooke https://github.com/inky/automeme.

Install
=======

git clone git@github.com:rupa/automeme.git
cd automeme
python setup.py sdist
pip install dist/automeme*tar.gz

Usage
=====

>>> from automeme import generate
>>> generate()
"YOU WOULDN'T DOWNLOAD AN ANT"

A CLI script is included:

~$ automeme
BANK'S CLOSED DUE TO EXTRA LIVES
61 changes: 0 additions & 61 deletions README.markdown

This file was deleted.

52 changes: 22 additions & 30 deletions src/meme.py → automeme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import re
from random import choice

# note: python parses 'coding=' above

__author__ = 'Liam Cooke <http://boxofjunk.ws/>'

from random import randint

from common import *
from patterns import patterns
from vocab import vocab as primary_vocab

CONTENT_TYPES = {'html': 'text/html', 'txt': 'text/plain', 'plain': 'text/plain'}
title = 'AUTOMEME'


# SOPA/PIPA blackout
import datetime
BLACKOUT_TIME = datetime.datetime.now().timetuple()[:3] == (2012, 1, 18)

expand = lambda v: (callable(v) and [v()] or [v])[0]
re_sub = lambda p, r, s: re.compile(p, re.U | re.VERBOSE).sub(r, s)

def get_word(words, index):
"""Return a word from a list of words. If the word contains
the character ~, this is replaced with the word at index-1.
"""
v = min(index, len(words)-1)
Return a word from a list of words. If the word contains
the character ~, this is replaced with the word at index - 1.
"""
v = min(index, len(words) - 1)
if '~' in words[v]:
return words[v].replace('~', v > 0 and get_word(words, v-1) or '')
return words[v].replace('~', v > 0 and get_word(words, v - 1) or '')
return words[v]

def randword(category, vocab):
"""Return a random word using a specified word category or
"""
Return a random word using a specified word category or
list of word categories. A category is denoted by one of
the following formats:
X category X, variant 0
Expand Down Expand Up @@ -67,7 +56,9 @@ def randword(category, vocab):
return get_word(vars, var)

def a_word(word):
"""Prepend 'a' or 'an' to a word."""
"""
Prepend 'a' or 'an' to a word.
"""
w = word.split(' ', 1)[0].lower()
if w in ('unix', ):
return 'a ' + word
Expand All @@ -76,9 +67,10 @@ def a_word(word):
else:
return 'a ' + word

def generate(format='html', pattern='', vocab=None):
if BLACKOUT_TIME:
return 'I MADE U A MEME BUT SOPA EATED IT'
def generate(format='plain', pattern='', vocab=None):
"""
MAKE YOU A MEME
"""

mode = vocab
if mode == 'hipster':
Expand All @@ -104,14 +96,14 @@ def generate(format='html', pattern='', vocab=None):
else:
p = expand(p[0])

meme = expand( p[0] )
meme = expand(p[0])
subs = p[1:]

for i, s in enumerate(subs):
word = randword(s, vocab)
meme = meme.replace('{%s}' % (i+1), word)
if '{%sa}' % (i+1) in meme:
meme = meme.replace('{%sa}' % (i+1), a_word(word))
meme = meme.replace('{%s}' % (i + 1), word)
if '{%sa}' % (i + 1) in meme:
meme = meme.replace('{%sa}' % (i + 1), a_word(word))

meme = meme.upper()
if format in ('plain', 'twitter'):
Expand Down
File renamed without changes.
Loading

0 comments on commit 1de546c

Please sign in to comment.