Skip to content

Instantly share code, notes, and snippets.

@commadelimited
Created May 20, 2014 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commadelimited/aeeb7c1b5bea604f04b7 to your computer and use it in GitHub Desktop.
Save commadelimited/aeeb7c1b5bea604f04b7 to your computer and use it in GitHub Desktop.
  • Save random_wiki.py to your desktop
  • Run pip install pyquery
  • In your terminal run python wiki.py | say
  • Enjoy
import requests
from pyquery import PyQuery as pq
def retrieve_article():
wiki_link = 'http://en.wikipedia.org/wiki/Special:Random'
article = requests.get(wiki_link)
text = pq(article.text)
first_paragraph = text('#mw-content-text').find('p').eq(0).text()
if first_paragraph == None or first_paragraph == '':
retrieve_article()
else:
print first_paragraph + '\n\n' + article.url
if __name__ == '__main__':
retrieve_article()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment