Created
March 25, 2016 02:55
-
-
Save nikhiljha/52935ad096ac3e07ec73 to your computer and use it in GitHub Desktop.
Look up things on Wikipedia in the command line!
This file contains hidden or 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
# Usage: python wikipedia.py | |
# Look up things on Wikipedia in the command line! | |
import requests; | |
import json; | |
learn = input('Learn About ') | |
for x in learn: | |
if x == ' ': | |
x = '%20' | |
r = requests.get('https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&redirects=1&titles=' + learn); | |
parse = json.loads(r.content.decode('utf-8')); | |
pages = parse['query']['pages']; | |
text = 'error'; | |
for n in pages: | |
text = parse['query']['pages'][n]['extract']; | |
print(text.encode('utf-8').decode('utf-8')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment