- Save random_wiki.py to your desktop
- Run
pip install pyquery
- In your terminal run
python wiki.py | say
- Enjoy
Created
May 20, 2014 15:52
-
-
Save commadelimited/aeeb7c1b5bea604f04b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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