Skip to content
Merged
Changes from 5 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
25 changes: 6 additions & 19 deletions modules/headline.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import urllib.request
from bs4 import BeautifulSoup
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob
import newspaper

class title:

#Initialisations
def __init__(self):
self.news_url="https://edition.cnn.com/2019/08/25/politics/trump-g7-boris-johnson-emmanuel-macron/index.html"


def extract_headline(self):
self.net_con=True #Expecting Internet Connection to be working initially
try:
news_page=urllib.request.urlopen(self.news_url)
soup = BeautifulSoup(news_page,'html.parser')
headline_in_html=soup.find('h1')
headline=headline_in_html.text.strip()
return headline

except urllib.error.URLError:
print("\nCONNECTIION ERROR:There may be a connection problem. Please check if the device is connected to the Internet")
self.net_con=False #Value update if the program is unable to connenct

article = newspaper.Article(self.news_url)
article.download()
article.parse()
return article.title.strip()

#Adding Training Data
def train_data(self, headline):
Expand All @@ -33,10 +23,7 @@ def train_data(self, headline):
return sentiment

except:
if self.net_con==False:
pass
else:
print("\n\nProgram Error")
print("\n\n Connection/Program Error")


def headline_category(self,headline,sentiment):
Expand Down