Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Builder Design Pattern #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
75 changes: 75 additions & 0 deletions scraping/ScrapeRss/rss_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,79 @@
YEAR_MONTH_DAY_FORMAT,
)

from abc import ABCMeta, abstractmethod

class INewsSourceBuilder(metaclass = ABCMeta):
"The Builder Interface"

@staticmethod
@abstractmethod
def build_url():
pass

@staticmethod
@abstractmethod
def build_title():
pass

@staticmethod
@abstractmethod
def build_description():
pass

@staticmethod
@abstractmethod
def build_data_xml():
pass

@staticmethod
@abstractmethod
def get_news():
pass

class NewsSource(INewsSourceBuilder):
"concrete builder"

def __init__(self):
self.Product = Product()

def build_url(self, url):
self.url = url
return self

def build_title(self, title):
self.title = title
return self

def build_description(self, description):
self.description = description
return self

def build_data_xml(self, data_xml):
self.data_xml = data_xml
return self

def get_News(self):
return self.product

class Product():
"the products"

def __init__(self):
self.news = []

class Director:
"the director, building a complex representation"

@staticmethod
def construct():
"constructs and return final products"
return Builder()\
.build_url()\
.build_title()\
.build_description()\
.build_data_xml()\
.get_news()

NEWS_SOURCES = {
"de_DE": [
Expand Down Expand Up @@ -566,3 +639,5 @@
),
],
}

NEWS = Director.construct()