rename entrie handler

This commit is contained in:
stubbfel
2014-08-31 21:48:44 +02:00
parent 4cb8a73190
commit 642dfa2d0c
11 changed files with 404 additions and 104 deletions

12
src/feed/FeedEntry.py Normal file
View File

@@ -0,0 +1,12 @@
__author__ = 'dev'
class FeedEntry:
class Status:
New = "New"
Loading = "Loading"
Loaded = "Loaded"
class KeyName:
EntryKey = "entries"
EntryStatusKey = "EntryStatus"

29
src/feed/entry_handler.py Normal file
View File

@@ -0,0 +1,29 @@
__author__ = 'dev'
from feed.feed import Feed
import utilities.file_methods as fm
from feed.FeedEntry import FeedEntry
class EntryHandler():
def __init__(self, feed):
assert isinstance(feed, Feed)
self._feed = feed
def handle_entries(self):
for entry in self.detect_new_entries():
self.handle_entry(entry)
def detect_new_entries(self):
new_links = []
for entry in fm.read_json_file(self._feed.feed_file_path)[FeedEntry.KeyName.EntryKey]:
status = entry.get(FeedEntry.KeyName.EntryStatusKey)
if status is None or status == FeedEntry.Status.New:
new_links.append(entry)
return new_links
def handle_entry(self, link):
pass

View File

@@ -2,6 +2,7 @@ __author__ = 'dev'
from config.config import Config
from utilities.podcastserializer import PodcastSerializer
from utilities.serializer import Serializer
import feedparser
import os
import utilities.file_methods as fm
@@ -62,8 +63,9 @@ class Feed:
:return: Serializer - the serializer of the feed
"""
return {
"podcast": PodcastSerializer(self.feed_config["LinkType"])
}.get(self.feed_config["FeedType"], PodcastSerializer(self.feed_config["LinkType"]))
"podcast": PodcastSerializer(self.feed_config["LinkType"]),
"rss": Serializer()
}.get(self.feed_config["FeedType"], Serializer())
def setup_feed(self, feed_name, feed_type, link_type, feed_url):
"""

View File

@@ -0,0 +1,5 @@
__author__ = 'dev'
class PodcastKeys:
FileLink = "file_link"
FileLength = "length"

View File

@@ -6,6 +6,7 @@ from config.config import Config
RSS_Prefix = "<?xml version=\"1.0\"?><rss version=\"2.0\"><channel>"
RSS_Suffix = "</channel></rss>"
class PodcastSerializer(Serializer):
def __init__(self, episode_file_type):
@@ -20,35 +21,35 @@ class PodcastSerializer(Serializer):
"""
assert isinstance(dict_object, dict)
episodeList = []
episode_list = []
for episode in dict_object["entries"]:
filelink = ""
file_link = ""
file_length = ""
for links in episode["links"]:
if links["type"] == self.episode_file_type and links["rel"] == "enclosure":
filelink = links["href"]
file_link = links["href"]
file_length = links["length"]
if filelink == "":
if file_link == "":
continue
tempepisode = {
temp_episode = {
"title": episode["title"],
"subtitle": episode["subtitle"],
"filelink": filelink,
"file_link": file_link,
"pubdate": episode["published"],
"length": file_length
}
episodeList.append(tempepisode)
episode_list.append(temp_episode)
tempdict = {
temp_dict = {
"title": dict_object["feed"]["title"],
"subtitle": dict_object["feed"]["subtitle"],
"summary": dict_object["feed"]["summary"],
"episodes": episodeList
"episodes": episode_list
}
return tempdict
return temp_dict
def serialize_rss(self, dict_object):
assert isinstance(dict_object, dict)
@@ -62,7 +63,7 @@ class PodcastSerializer(Serializer):
episodes_list += "<title>" + episode["title"] + "</title>"
episodes_list += "<description>" + episode["subtitle"] + "</description>"
episodes_list += "<pubDate>" + episode["pubdate"] + "</pubDate>"
episodes_list += "<enclosure url=\"" + episode["filelink"] + "\" type=\"" + self.episode_file_type + "\" length=\"" + episode["length"] + "\"/>"
episodes_list += "<enclosure url=\"" + episode["file_link"] + "\" type=\"" + self.episode_file_type + "\" length=\"" + episode["length"] + "\"/>"
episodes_list += "</item>"
return RSS_Prefix + rss_channel_info + episodes_list + RSS_Suffix