Skip to content

Commit 44648df

Browse files
authored
Add files via upload
Gives result about any topic from Wikipedia.
1 parent 7a8f418 commit 44648df

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

wiki_search.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import wikipedia
2+
import webbrowser
3+
4+
topic = input("Enter a topic to search: ")
5+
6+
try:
7+
# Get summary
8+
summary = wikipedia.summary(topic, sentences=4)
9+
print("\nResult:\n")
10+
print(summary)
11+
12+
# Ask if user wants full page
13+
choice = input("\nDo you want to open the full Wikipedia page? (yes/no): ").lower()
14+
if choice == "yes":
15+
page = wikipedia.page(topic)
16+
webbrowser.open(page.url)
17+
18+
except wikipedia.exceptions.DisambiguationError as e:
19+
print("Your search was too broad.")
20+
# print(e.options)
21+
except wikipedia.exceptions.PageError:
22+
print("No page found for that topic.")

0 commit comments

Comments
 (0)