Skip to content

Commit

Permalink
Refacotr formatter class
Browse files Browse the repository at this point in the history
  • Loading branch information
damklis committed Aug 3, 2020
1 parent 97b2233 commit 6b9673b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions airflow/modules/rss_news/rss_news_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,25 @@ def __init__(self):
self.default_author = "Unknown"

def format_entry(self, entry):
_id = self.construct_id(entry.title)
published_date = self.unify_date(entry.pub_date)
description = self.format_description(entry)
author = self.assign_author(entry.author)
language = self.detect_language(entry.title)
return News(
_id,
self.construct_id(entry.title),
entry.title,
entry.link,
published_date,
description,
author,
language
self.unify_date(entry.pub_date),
self.format_description(entry),
self.assign_author(entry.author),
self.detect_language(entry.title)
)
def assign_author(self, author):
return self.default_author if not author else author

def construct_id(self, title):
return re.sub(self.id_regex, "", title).lower()

def unify_date(self, date):
return date.strftime(self.date_format)

def assign_author(self, author):
return self.default_author if not author else author

@staticmethod
def format_description(entry):
tmp_description = re.sub("<.*?>", "", entry.description[:1000])
Expand Down

0 comments on commit 6b9673b

Please sign in to comment.