A MINI PROJECT
on
“News summaraizer”
Submitted to
AI tools Lab
BACHELOR OF TECHNOLOGY
IN
INFORMATION TECHNOLOGY
Submitted by
[Link] krishna reddy 21121A3535
[Link] reddy 21121A3515
[Link] Prakash reddy 21121A3513
[Link] Avinash 21121A3549
[Link] 21121A3509
Department of Information
Technology
SREE VIDYANIKETHAN ENGINEERING COLLEGE
(AUTONOMOUS)
(Affiliated to JNTUA, Anantapur, Approved by AICTE, Accredited by NBA & NAAC)
Sree Sainath Nagar, Tirupati – 517 102, A.P., INDIA
2023-2024
1
TABLE OF CONTENTS
1. Abstract .........................................................................2
2. Keywords ......................................................................2
3. Introduction...................................................................2
4. CODE…………………………………………………2
5. Explanation……………………………………………2
6. CONCLUSION……………………………………….6
7. REFERENCES……………………………………….6
2
Abstract
This Python code utilizes various libraries for web scraping and natural
language processing. It begins by importing necessary modules, including tkinter for creating a graphical
user interface, nltk for natural language processing tasks, Textblob for higher-level text analysis, and
newspaper for extracting and parsing articles from websites.
The code is designed to fetch and analyze an article from a specified URL. It employs a custom user
agent string to mimic a web browser, helping to retrieve content from the site. The program attempts to
download, parse, and process the article, while also accounting for potential exceptions that may occur
during the process.
If the code successfully processes the article, it prints out relevant information such as the article's title,
authors, publication date, and a summary generated through natural language processing techniques. It
also includes error handling to address any issues that may arise during execution.
Overall, this code serves as a foundation for building a program that can fetch and analyze web-based
articles, making it a useful tool for tasks related to web scraping and text analysis.
Keywords:
1. tkinter
2. TextBlob
3. newspaper
4. user agent
5. url
6. exception handling
7. download
8. parse
9. natural language processing
10. article analysis
11. summary generation
12. error handling
These keywords capture the main components and concepts involved in the
provided code snippet, ranging from GUI development to web scraping, NLP, and error handling.
Introduction:
A news summarizer is a sophisticated computational tool designed to
distill the essential information from lengthy news articles, enabling users to quickly grasp the key points
without having to read the entire text. By leveraging advanced natural language processing (NLP)
techniques, news summarizers analyze the content, identify important details, and generate concise
summaries. This technology addresses the challenge of information overload in today's rapidly evolving
digital landscape, where a surplus of news articles can be overwhelming. News summarizers serve as
invaluable tools for professionals, researchers, and individuals seeking to stay informed efficiently. They
not only save time but also enhance accessibility by providing clear and condensed insights into news
stories. Additionally, some summarizers offer customization options, allowing users to tailor summaries
to their specific interests or areas of expertise. While immensely beneficial, it's important to acknowledge
3
that the effectiveness of a news summarizer depends on the sophistication of its underlying algorithms
and the complexity of the source material. Despite this, news summarizers play a crucial role in
facilitating quick and efficient access to relevant information in today's information-rich society.
Code:
import tkinter as tk
import nltk
from textblob import TextBlob
from newspaper import Article
from newspaper import Config
[Link]('punkt')
url = "[Link]
config = Config()
config.browser_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/99.0.9999.999 Safari/537.36"
try:
article = Article(url, config=config)
[Link]()
[Link]()
[Link]()
except Exception as e:
print(f"An error occurred: {str(e)}")
article = None
if article:
print(f'Title: {[Link]}')
print(f'Authors: {[Link]}')
print(f'Publication Date: {article.publish_date}')
print(f'Summary: {[Link]}')
Explanation:
Certainly! This code is a Python script that uses the ‘newspaper’ library along with other libraries like
`nltk` and `TextBlob` to extract information from a specified news article available at a given URL.
Here’s an explanation of the code:
1. Import Libraries:
- `tkinter as tk`: Imports the `tkinter` library, which is typically used for creating graphical user
interfaces (GUIs). In this code, it is not directly used.
- ‘nltk’: Imports the Natural Language Toolkit (NLTK), a library used for natural language processing
tasks.
- ‘TextBlob’: Imports the ‘TextBlob’ class from the ‘textblob’ library, which is used for processing
and analyzing text.
- `Article` and `Config`: Import the `Article` class and `Config` class from the `newspaper` library.
The `Article` class is used to represent and process a news article, and `Config` is used to configure
the behavior of the `newspaper` library, including setting the user-agent.
4
2. Download NLTK’s ‘punkt’ Package:
- `[Link](‘punkt’)`: Downloads the NLTK ‘punkt’ package, which is necessary for tokenizing
text into words or sentences.
3. Define the URL:
- ‘url = “[Link] Specifies the URL of the
news article to be processed. In this code, it’s set to a BBC News article in the “Science &
Environment” section.
4. Create a Configuration with User-Agent:
- `config = Config()`: Initializes a configuration object from the `newspaper` library.
- `config.browser_user_agent = “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/99.0.9999.999 Safari/537.36”: Sets a user-agent string to mimic a web
browser when making requests to the specified URL. This helps avoid issues with websites that may
block or limit requests from unrecognized user agents.
5. Try-Except Block for Article Processing:
- A `try` block is used to attempt to process the article. Inside the `try` block, the code performs the
following actions:
- Initializes an `Article` object with the given URL and configuration.
- Downloads the article content from the URL.
- Parses the article to extract its main content.
- Performs natural language processing (NLP) on the article, such as tokenization and extracting
keywords.
- An `except` block is used to catch and handle exceptions. If an error occurs during any of the
above steps, it will be caught, and an error message will be printed to the console. The `article`
object is set to `None` if there is an error.
6. Display Article Information (If Available):
- After processing the article, the code checks if the `article` object is not `None`. If it’s not `None`,
it means the article was successfully processed.
- The code then prints various details of the article, including its title, authors, publication date, and
a summary. These details are extracted from the processed article.
This code allows you to extract and display information from a news article, such as its title, authors,
publication date, and a summary, for further analysis or use in other applications.
Conclusion:
In conclusion, news summarization stands at the forefront of technological advancements in information
processing, offering a powerful solution to the challenge of information overload in today's digital age.
By harnessing the capabilities of natural language processing and machine learning, news summarizers
provide users with the ability to swiftly distill key insights from extensive articles, saving time and
enhancing accessibility. The potential for future work in this field is vast, spanning areas like multi-
lingual summarization, domain-specific models, real-time updates, and personalized summaries. As
research and development in news summarization continue to evolve, we anticipate a future where
5
individuals and professionals alike can effortlessly navigate the sea of information, staying informed and
making well-informed decisions with ease. The continued refinement of these technologies promises to
revolutionize how we consume news and information, ultimately empowering us in an era of
unprecedented data abundance.
References:
[1] Sadeghi, S. H. R., et al. "Soil Moisture Sensors: A Review." Journal of Sensors.
Hindawi, 2017.
[2] Rasmussen, K. J., et al. "Soil Moisture Measurement and Sampling Depth Affects
Water Uptake Estimates in Woody and Herbaceous Species." PloS one. Public
Library of Science, 2016.
[3] Kamilaris, Andreas, and Francesc X. Prenafeta-Boldú. "Deep Learning in
Agriculture: A Survey." Computers and Electronics in Agriculture. Elsevier, 2018.
[4] FAO. "The State of Food and Agriculture 2019. Moving Forward on Food Loss
and Waste Reduction." Food and Agriculture Organization of the United Nations, 2019.
[5] United Nations. "Sustainable Development Goals." United Nations, 2015.