Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8b3609f

Browse files
committed
Create Wikipedia bot in Python
1 parent 9adb41d commit 8b3609f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

‎W/Wikipedia bot/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Wikipedia bot in Python #
2+
3+
👋 Hi there!
4+
5+
## About the project ##
6+
7+
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.
8+
9+
## Installation and use ##
10+
11+
1) Install the dependency
12+
13+
```pip3 install wikipedia```
14+
15+
2) Run the application
16+
17+
```python3 Wikipedia_bot.py```
18+
19+
3) Happy learning!
20+
21+
## Bugs and improvements ###
22+
23+
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!
24+
25+
2) This app could definitely use a GUI
26+

‎W/Wikipedia bot/Wikipedia_bot.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import wikipedia as wiki # Import the library
2+
3+
topic = input("Please enter the topic: ")
4+
results = wiki.search(topic) # Search for related articles
5+
print("[+] Found", len(results), "entries!")
6+
print("Select the article: ")
7+
for index, value in enumerate(results): # Give the user an opportunity to choose between the articles
8+
print(str(index)+ ")"+" "+str(value))
9+
10+
print("\n")
11+
article = int(input())
12+
try: # Try retrieving info from the Wiki page
13+
page = wiki.page(results[article])
14+
print(str(page.title).center(1000))
15+
print(page.url)
16+
print(wiki.summary(results[article], sentences=1))
17+
except DisambiguationError as e: # Workaround for the disambiguation error
18+
print("[-] An error occured!")
19+
print("URL: "+"https://en.wikipedia.org/wiki/"+str(results[article]).replace(' ', '_'))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /