Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@
| 74 | [Dinosaur Game](/Python/dinosaur_game) | The famous Chrome dinosaur game when there is no Internet | [Ian Yy](https://github.com/Ian-Yy) |
| 75 | [Speech to Text Converter](/Python/speech-to-text) | Converts speech from a WAVE file to text. | [Dishant Vyas](https://github.com/dishantvyas15) |
| 76 | [2048 Game](/Python/2048_Stack) | The 2048 game using a stack | [Yash Brid](https://github.com/bridyash13)
| 77 | [Wikipedia Search Wordcloud](/Python/Wikipedia%20Search%20Wordcloud) | Wordcloud generated based on Wikipedia search word content | [Naman Shah](https://github.com/namanshah01)
12 changes: 12 additions & 0 deletions Python/Wikipedia Search Wordcloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Wordcloud Images for Wikipedia Article
Python script that prompts the user for an input, searches for the corresponding article on wikipedia and generates a wordcloud based on the searched article.

### Prerequisites
`pip install` the models in `requirements.txt` from your command prompt.

### How to run the script
Run like any other python file. Upon executing, the wordcloud image will be saved to the current directory. The script will also prompt a y/n if the user wants to see the generated image during execution.
![script execution](script_execution.jpg)

### Author
[Naman Shah](https://github.com/namanshah01)
17 changes: 17 additions & 0 deletions Python/Wikipedia Search Wordcloud/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
beautifulsoup4==4.9.1
certifi==2020.6.20
chardet==3.0.4
cycler==0.10.0
idna==2.10
kiwisolver==1.2.0
matplotlib==3.3.1
numpy==1.19.1
Pillow==7.2.0
pyparsing==2.4.7
python-dateutil==2.8.1
requests==2.24.0
six==1.15.0
soupsieve==2.0.1
urllib3==1.25.10
wikipedia==1.4.0
wordcloud==1.8.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions Python/Wikipedia Search Wordcloud/wiki-search-cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
import matplotlib.pyplot as plt
import wikipedia
import sys
import warnings
warnings.filterwarnings("ignore")

def gen_cloud(topic):
try:
content = str(wikipedia.page(topic).content[:5000])
except:
print("Error, try searching something else...")
sys.exit()
STOPWORDS.add('==')
stopwords = set(STOPWORDS)
wordcloud = WordCloud(stopwords=stopwords, max_words=200, background_color="black", width=600, height=350).generate(content)
return wordcloud

def save_cloud(wordcloud):
wordcloud.to_file("./wordcloud.png")

def show_cloud(wordcloud):
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()

if __name__ == '__main__':
topic = input("What do you want to search: ").strip()
wordcloud = gen_cloud(topic)
save_cloud(wordcloud)
print("Wordcloud saved to current directory as wordcloud.png")
desc = input("Do you wish to see the output(y/n): ")
if desc == 'y':
show_cloud(wordcloud)
sys.exit()
Binary file added Python/Wikipedia Search Wordcloud/wordcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.