Skip to content

Instantly share code, notes, and snippets.

@ryonsherman
Last active January 4, 2016 04:29
Show Gist options
  • Save ryonsherman/d079d24e53b84c55c0ae to your computer and use it in GitHub Desktop.
Save ryonsherman/d079d24e53b84c55c0ae to your computer and use it in GitHub Desktop.
Console `fortune` command output
#!/usr/bin/env python2
from subprocess import Popen, PIPE
def fortune(db=''):
f = Popen(['fortune', db], stdout=PIPE).communicate()[0]
return unicode(f).strip().encode('ascii', 'xmlcharrefreplace')
@ryonsherman
Copy link
Author

Exposing method to Jinja template environment

jinja_env.globals.update(fortune=fortune)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment