Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
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
12 changes: 12 additions & 0 deletions projects/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 Name*
[Naman Shah](https://github.com/namanshah01)
17 changes: 17 additions & 0 deletions projects/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.
44 changes: 44 additions & 0 deletions projects/Wikipedia Search Wordcloud/wiki-search-cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
import matplotlib.pyplot as plt
import wikipedia
import sys
import warnings
# supressing unnecessary warnings
warnings.filterwarnings("ignore")


# function to search the wikipedia article and generate the wordcloud
def gen_cloud(topic):
try:
content = str(wikipedia.page(topic).content)
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


# function to save the wordcloud to current directory
def save_cloud(wordcloud):
wordcloud.to_file("./wordcloud.png")


# function to display the wordcloud with matplotlib
def show_cloud(wordcloud):
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()


# driver code
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.