Skip to content

renamed extract_headline to extract_article, reduced the function cal…#18

Open
riseandshine0 wants to merge 1 commit into
Learning-Python-Team:masterfrom
riseandshine0:master
Open

renamed extract_headline to extract_article, reduced the function cal…#18
riseandshine0 wants to merge 1 commit into
Learning-Python-Team:masterfrom
riseandshine0:master

Conversation

@riseandshine0

Copy link
Copy Markdown
Collaborator

…l for downloading the article to 1

Comment thread modules/headline.py
try:
self.article.download()
self.article.parse()
return self.article

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to return the article since only the connection adapters need to be downloaded and parsed. Returning does not do anything since the article is already defined in self.article.

Comment thread modules/headline.py
self.article.download()
self.article.parse()
return self.article
except newspaper.article.ArticleException: # List possible errors in case of any exception

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this issue; #17
We could also simply say;

except newspaper.article.ArticleException as e:
    print(e)

Comment thread modules/headline.py
self.neg = [] # Variable to store all negative tokens from negative_headlines.csv file
self.article = newspaper.Article(self.news_url)

# extract headline

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# extract article

Comment thread modules/headline.py

# Initialisations
def __init__(self):
self.news_url = input("\nEnter The URL : ")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider working with config files, requirement files and readme.md's from now on. This improves readability, efficiency and minimizes the chance someone fricks with the code.

Comment thread modules/headline.py

# main of class
def main(self):
article = self.extract_article()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you define article here if self.article is already initiated?
There are 2 ways around this;

  1. Instead of article = self.extract_article() say self.extract_article()
  2. In def __init__ make self.article = self.extract_article() where the entired article is initiated, downloaded and parsed. Here you would want the return.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants