-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from pyerie/main
Create Wikipedia bot(not a duplicate)
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Wikipedia bot in Python # | ||
|
||
👋 Hi there! | ||
|
||
## About the project ## | ||
|
||
This is a simple Wikipedia surfing bot in Python made with the wikipedia library. It allows the user to search for a topic and choose between the articles related to it. Once the user has chosen the article, it provides the link to the article and summarizes it in a line. | ||
|
||
## Installation and use ## | ||
|
||
1) Install the dependency | ||
|
||
```pip3 install wikipedia``` | ||
|
||
2) Run the application | ||
|
||
```python3 Wikipedia_bot.py``` | ||
|
||
3) Happy learning! | ||
|
||
## Bugs and improvements ### | ||
|
||
1) When trying to load the page of some articles, the program encounters a disambiguation error that suggests some other(totally unrelated) articles. I can't seem to fix it(found a workaround tho). Any help is appreciated! | ||
|
||
2) This app could definitely use a GUI | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import wikipedia as wiki # Import the library | ||
|
||
topic = input("Please enter the topic: ") | ||
results = wiki.search(topic) # Search for related articles | ||
print("[+] Found", len(results), "entries!") | ||
print("Select the article: ") | ||
for index, value in enumerate(results): # Give the user an opportunity to choose between the articles | ||
print(str(index)+ ")"+" "+str(value)) | ||
|
||
print("\n") | ||
article = int(input()) | ||
try: # Try retrieving info from the Wiki page | ||
page = wiki.page(results[article]) | ||
print(str(page.title).center(1000)) | ||
print(page.url) | ||
print(wiki.summary(results[article], sentences=1)) | ||
except DisambiguationError as e: # Workaround for the disambiguation error | ||
print("[-] An error occured!") | ||
print("URL: "+"https://en.wikipedia.org/wiki/"+str(results[article]).replace(' ', '_')) |