Skip to content

Commit

Permalink
Merge pull request #297 from pyerie/main
Browse files Browse the repository at this point in the history
Create Wikipedia bot(not a duplicate)
  • Loading branch information
Techiral authored Oct 6, 2024
2 parents 93b3fc9 + 8b3609f commit 06925c8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
26 changes: 26 additions & 0 deletions W/Wikipedia bot/README.md
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

19 changes: 19 additions & 0 deletions W/Wikipedia bot/Wikipedia_bot.py
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(' ', '_'))

0 comments on commit 06925c8

Please sign in to comment.