wikipedia.py 615 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python
  2. import requests
  3. import json
  4. import os
  5. import sys
  6. import re
  7. bold = "\033[01m"
  8. norm = "\033[00m"
  9. bright_cyan = "\033[46m"
  10. colora = "\033[45m"
  11. colorb = "\033[44m"
  12. search = input("Wikipedia Snippet: ")
  13. wikipedia_api = f"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={search}&format=json"
  14. data = requests.get(wikipedia_api)
  15. json_stuff = json.loads(data.text)
  16. for index, post in enumerate(json_stuff["query"]["search"]):
  17. clean = re.compile('<.*?>')
  18. print(re.sub(clean, '', post["title"]+"\n"+post["snippet"]+"\n"))
  19. if index == 2:
  20. break