Closed yuvi1323 closed 3 weeks ago
Iterated on issues realted to this and kept a limit to stopword setter to 10 keywords
`import requests import csv import matplotlib.pyplot as plt from wordcloud import WordCloud
query = input("Enter a keyword to search for: ") num_articles = int(input("Enter the number of articles to retrieve: ")) filename = input("Enter a filename to save the CSV data: ")
articles = []
num_pages = (num_articles - 1) // 100 + 1 # Calculate number of pages needed for i in range(num_pages): response = requests.get(url.format(i + 1)) if response.status_code == 200: data = response.json() articles += data["articles"] else: print("Error:", response.status_code) break
with open(filename + ".csv", "w", newline="", encoding="utf-8") as csvfile: fieldnames = ["title", "description"] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for article in articles: writer.writerow({"title": article["title"], "description": article["description"]})
show_wordcloud = input("Do you want to see the word cloud visualization? (yes/no): ").lower() == "yes"
if show_wordcloud:
with open(filename + ".csv", encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
text = ""
for row in reader:
text += row['description'] + " "
# Generate word cloud
wordcloud = WordCloud(width=800, height=800, background_color='white').generate(text)
# Display the generated wordcloud image
plt.figure(figsize=(8,8), facecolor=None)
plt.imshow(wordcloud)
plt.axis("off")
plt.tight_layout(pad=0)
plt.show()
`
Hi @Girishkolapalli reviewed your code all issues are fine
Estimation Time: Medium (3 days) Acceptance Criteria: