Skip to content

Instantly share code, notes, and snippets.

@alphapapa
Created November 7, 2014 05:02
Show Gist options
  • Save alphapapa/38fbaa4fed609bb0a5e0 to your computer and use it in GitHub Desktop.
Save alphapapa/38fbaa4fed609bb0a5e0 to your computer and use it in GitHub Desktop.
w: Print summary of Wikipedia article to STDOUT
#!/usr/bin/env python
# Requires wikipedia module. '$ pip install wikipedia' Put it in your
# path and 'chmod +x'. Then just 'w whatever' and find out what
# something is! :D
# I couldn't find a good command-line utiity to do this.
# wikipedia2text is okay but it does the whole page, which isn't
# always what I want. The old command 'dig +short txt "$1.wp.dg.cx"'
# doesn't work anymore. But this works well.
import sys
try:
import wikipedia as wp
except:
print "Requires the wikipedia module. Use 'pip install wikipedia' to install."
sys.exit(1)
s = wp.summary(str(sys.argv[1:]))
print s.replace('\n', '\n\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment