add coments
This commit is contained in:
@@ -9,6 +9,13 @@ import utilities.file_methods as fm
|
||||
|
||||
class Feed:
|
||||
def __init__(self, feed_name=None, feed_type=None, link_type=None, feed_url=None):
|
||||
"""
|
||||
method ini a feed object
|
||||
:param feed_name: str - name of the feed
|
||||
:param feed_type: str - type of the feed
|
||||
:param link_type: str - application type of the episodes
|
||||
:param feed_url: str - url of the feed
|
||||
"""
|
||||
self.config_path = None
|
||||
self.feed_folder_path = None
|
||||
self.feed_config = None
|
||||
@@ -18,16 +25,26 @@ class Feed:
|
||||
self.setup_feed(feed_name, feed_type, link_type, feed_url)
|
||||
|
||||
def load_feed(self):
|
||||
"""
|
||||
method load a feed from the FeedUrl
|
||||
:return: FeedParserDict - the feed as a dict
|
||||
"""
|
||||
assert self.feed_config is not None
|
||||
return feedparser.parse(self.feed_config["FeedUrl"])
|
||||
|
||||
def load_new_feed(self):
|
||||
"""
|
||||
method load a feed and write the feed json file, which has no feed folder
|
||||
"""
|
||||
assert (not os.path.exists(self.feed_file_path))
|
||||
assert (self.serializer is not None)
|
||||
fm.write_feed_json_file(self.feed_file_path, self.load_feed(), self.serializer)
|
||||
|
||||
def load_existing_feed(self):
|
||||
|
||||
"""
|
||||
method load a feed and write the feed json file, which has a feed folder
|
||||
"""
|
||||
assert (os.path.exists(self.feed_file_path))
|
||||
assert (self.serializer is not None)
|
||||
|
||||
@@ -40,11 +57,22 @@ class Feed:
|
||||
fm.check_and_remove_file(tmp_feed_file_path)
|
||||
|
||||
def get_serializer(self):
|
||||
"""
|
||||
Method get the correct serializer
|
||||
:return: Serializer - the serializer of the feed
|
||||
"""
|
||||
return {
|
||||
"podcast": PodcastSerializer(self.feed_config["LinkType"])
|
||||
}.get(self.feed_config["FeedType"], PodcastSerializer(self.feed_config["LinkType"]))
|
||||
|
||||
def setup_feed(self, feed_name, feed_type, link_type, feed_url):
|
||||
"""
|
||||
method create, read, write the feed config, determine serializer
|
||||
:param feed_name: str - name of the feed
|
||||
:param feed_type: str - type of the feed
|
||||
:param link_type: str - application type of the episodes
|
||||
:param feed_url: str - url of the feed
|
||||
"""
|
||||
assert feed_name is not None
|
||||
assert feed_type is not None
|
||||
assert link_type is not None
|
||||
@@ -59,7 +87,10 @@ class Feed:
|
||||
self.serializer = self.get_serializer()
|
||||
|
||||
def new_feed_folder(self):
|
||||
|
||||
"""
|
||||
method creates a feed folder
|
||||
:return: str - return the path of the new folder
|
||||
"""
|
||||
if self.feed_folder_path is None:
|
||||
assert self.feed_config is not None
|
||||
self.feed_folder = Config.get("FeedStorageFolder")
|
||||
@@ -84,16 +115,32 @@ class Feed:
|
||||
return self.feed_folder_path
|
||||
|
||||
def create_feed_config_path(self):
|
||||
"""
|
||||
method determine the path of the config file
|
||||
:return: str - path of the config file
|
||||
"""
|
||||
if self.config_path is None:
|
||||
self.config_path = self.new_feed_folder() + "/" + self.feed_config["FeedName"] + Config[
|
||||
"ConfigFileSuffix"] + Config["ConfigFileExtension"]
|
||||
return self.config_path
|
||||
|
||||
def write_feed_config_file(self):
|
||||
"""
|
||||
method write the config file
|
||||
"""
|
||||
assert (self.feed_config is not None)
|
||||
fm.write_json_file(self.create_feed_config_path(), self.feed_config)
|
||||
|
||||
@staticmethod
|
||||
def create_feed_config_file(feed_name, feed_type, link_type, feed_url):
|
||||
"""
|
||||
method creates a config dict
|
||||
:param feed_name: str - name of the feed
|
||||
:param feed_type: str - type of the feed
|
||||
:param link_type: str - application type of the episodes
|
||||
:param feed_url: str - url of the feed
|
||||
:return: dict : config of the feed
|
||||
"""
|
||||
assert feed_name is not None
|
||||
assert feed_type is not None
|
||||
assert link_type is not None
|
||||
|
||||
@@ -8,8 +8,7 @@ class Serializer():
|
||||
method convert i dict to a string.
|
||||
this method should be override by any subclasses
|
||||
:param dict_object: object wich his to bee convert to a string
|
||||
:return: rhe string reprasention of the dict_object
|
||||
:depicated
|
||||
:return: the string reprasention of the dict_object
|
||||
"""
|
||||
assert isinstance(dict_object, dict)
|
||||
return dict_object
|
||||
Reference in New Issue
Block a user