Skip to content

Instantly share code, notes, and snippets.

@trdarr
Created February 26, 2014 04:00
Show Gist options
  • Save trdarr/9223285 to your computer and use it in GitHub Desktop.
Save trdarr/9223285 to your computer and use it in GitHub Desktop.
wow. such pornmd. very live search terms. https://porndoge.herokuapp.com/
#!/usr/bin/env python
import flask
import operator
import random
import re
import requests
def get_terms(json, n=3):
'''Get a list of n acceptable random terms from the JSON array.'''
term_re = re.compile(r'[^a-z]')
get_term = operator.itemgetter('keyword')
def prepare_term(json):
'''Strip [^a-z] from each term and prefix a worde.'''
worde = random.choice(('such', 'very', 'much', 'many', 'so'))
return ''.join((worde, term_re.sub('', get_term(json))))
def get_some_terms(json):
'''Get a list of random terms from the JSON array.'''
choices = map(lambda _: random.choice(json), xrange(n))
return map(prepare_term, choices)
def terms_are_okay(terms):
'''Check that terms are okay.'''
return not any(map(lambda term: len(term) >= 25, terms))
# Get some terms until they're acceptable.
while True:
terms = get_some_terms(json)
if terms_are_okay(terms):
terms += ('wow',) * 2
random.shuffle(terms)
return terms
app = flask.Flask(__name__)
@app.route('/')
def index():
json = requests.get('http://www.pornmd.com/getliveterms').json()
doge = requests.get('http://dogr.io/{}.png'.format('/'.join(get_terms(json))))
return flask.Response(doge.content, mimetype='image/png')
if __name__ == '__main__':
app.run()
Flask==0.10.1
requests==2.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment