add create onif file and new folder
This commit is contained in:
@@ -4,5 +4,7 @@ Config = {
|
||||
"FeedLinkTypes" : {"application/x-bittorrent","mp3"},
|
||||
"FeedTypes" : {"podcast","rss"},
|
||||
"FeedStorageFolder" : "testfeeds",
|
||||
"FeedStoragePrefix" : { "0" : "FeedTypes"}
|
||||
"FeedStoragePrefix" : { "0" : "FeedType", "1" : "FeedName"},
|
||||
"ConfigFileSuffix" : "-config",
|
||||
"ConfigFileExtension" : ".json"
|
||||
}
|
||||
@@ -1,6 +1,49 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
from utilities.jsonfile import JsonFile
|
||||
from config.config import Config
|
||||
import os
|
||||
|
||||
class Feed:
|
||||
|
||||
def __init__(self):
|
||||
self.valid_file_types = {"application/x-bittorrent","mp3"}
|
||||
def __init__(self, feed_name=None, feed_type=None, link_type=None, feed_url=None):
|
||||
self.valid_file_types = {"application/x-bittorrent","mp3"}
|
||||
self.feed_config = self.create_feed_config_file(feed_name, feed_type, link_type, feed_url)
|
||||
|
||||
def new_feed_folder(self):
|
||||
feed_folder = Config["FeedStorageFolder"]
|
||||
feed_folder_prefix = Config["FeedStoragePrefix"]
|
||||
|
||||
for i in range(len(feed_folder_prefix)):
|
||||
value = feed_folder_prefix.get(str(i))
|
||||
if value is not None:
|
||||
tmpValue = self.feed_config.get(value)
|
||||
if tmpValue is not None:
|
||||
value = tmpValue
|
||||
|
||||
feed_folder += "/" + value
|
||||
else:
|
||||
break
|
||||
|
||||
if not os.path.exists(feed_folder):
|
||||
os.mkdir(feed_folder)
|
||||
|
||||
return os.path.abspath(feed_folder)
|
||||
|
||||
|
||||
|
||||
|
||||
def create_feed_config_file(self, feed_name, feed_type, link_type, feed_url):
|
||||
feed_config =\
|
||||
{
|
||||
"FeedName": feed_name,
|
||||
"FeedType": feed_type,
|
||||
"FeedUrl": feed_url,
|
||||
"LinkType": link_type
|
||||
}
|
||||
return feed_config
|
||||
|
||||
|
||||
def write_feed_config_file(self, feed_folder):
|
||||
file = JsonFile(feed_folder + self.feed_config["FeedName"] + Config["ConfigFileSuffix"] + Config["ConfigFileExtension"])
|
||||
file.write_json_file(self.feed_config)
|
||||
Reference in New Issue
Block a user