Skip to content

Instantly share code, notes, and snippets.

@YannBouyeron
Created June 21, 2020 18:39
Show Gist options
  • Save YannBouyeron/d85f4cd3c3c9cdaffdf447f11d06c7a6 to your computer and use it in GitHub Desktop.
Save YannBouyeron/d85f4cd3c3c9cdaffdf447f11d06c7a6 to your computer and use it in GitHub Desktop.
Wikipedia
#!/usr/bin/env python3.6
import wikipedia
import argparse
def searcher(x):
print("\n")
print("="*30 + " WIKIPEDIA " + "="*30)
print("\n")
print("\n")
result = wikipedia.search(x)
print("Result search of {0}: ".format(x), result)
print("\n")
page = wikipedia.page(result[0])
title = page.title
categories = page.categories
content = page.content
links = page.links
references = page.references
summary = page.summary
print("Page content:\n", content, "\n")
print("Page title:", title, "\n")
print("Categories:", categories, "\n")
print("Links:", links, "\n")
print("References:", references, "\n")
print("Summary:", summary, "\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Wikipedia")
parser.add_argument("search", help="Search on Wikipedia")
parser.add_argument("-l", "--lang", help="Change language")
args = parser.parse_args()
search, lang = args.search, args.lang
if args.lang:
wikipedia.set_lang(args.lang)
searcher(search)
@YannBouyeron
Copy link
Author

YannBouyeron commented Jun 21, 2020

Creat executable :

mv Wiki.py wiki
sudo chmod 755 wiki
sudo mv wiki /usr/local/bin

Use:

wiki trumpet 

Or for french Wikipedia:

wiki trompette -l fr 

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