Пример #1
0
def main():
    logging.basicConfig(filename = 'podcast.log', \
                        format = '%(asctime)s %(message)s', level = logging.INFO)

    cmn = common.common_functions()
    chatz = chatzinikolaou.chatzinikolaou_functions()
    url_chatz = cmn.config_section_map("chatzinikolaou")['url']

    if chatz.chatz_is_file_downloaded() == False:
        cmn.ensure_directory_structure('chatzinikolaou')
        main_page_html = cmn.get_html_and_split_lines(url_chatz)
        chatz_download_url = chatz.find_actual_download_url(main_page_html)
        download_page_html = cmn.get_html_and_split_lines(chatz_download_url)
        cmn.download_all_available_files(download_page_html, 'chatzinikolaou')
        cmn.concat_files_and_move("chatzinikolaou")
        rssgen = rss_gen.RssGenerator()
        rssgen.createxml("chatzinikolaou")
        logging.info(
            "New chatzinikolaou episode file found and podcast updated")
    else:
        logging.info("Exiting")

    ellin = ellinofreneia.ellinofreneia_functions()
    ellin_chatz = cmn.config_section_map("ellinofreneia")['url']

    if ellin.ellin_is_file_downloaded() == False:
        cmn.ensure_directory_structure('ellinofreneia')
        main_page_html = cmn.get_html_and_split_lines(ellin_chatz)
        ellin_download_url = ellin.find_actual_download_url(main_page_html)
        download_page_ellin_html = cmn.get_html_and_split_lines(
            ellin_download_url)
        cmn.download_all_available_files(download_page_ellin_html,
                                         'ellinofreneia')
        cmn.concat_files_and_move("ellinofreneia")
        rssgen = rss_gen.RssGenerator()
        rssgen.createxml("ellinofreneia")
        logging.info(
            "New ellinofreneia episode file found and podcast updated")
    else:
        logging.info("Exiting")
Пример #2
0
class ellinofreneia_functions:
    cmn = common.common_functions()
    now = datetime.datetime.now()
    base_url = cmn.config_section_map("ellinofreneia")['base_url']
    base_directory = cmn.config_section_map("home")['base_dir']

    def ellin_is_file_downloaded(self):
        flag = False
        complete_audio_file = "ellinofreneia"\
         + '_' + self.now.strftime("%d%m%Y") + '.mp3'
        rootdir = self.base_directory + "ellinofreneia"
        for path, subFolders, files in os.walk(rootdir):
            for file in files:
                if file == complete_audio_file:
                    logging.info('File with name %s already exists.', \
                                  complete_audio_file)
                    flag = True
        return flag

    def find_actual_download_url(self, html_lines):
        download_page = 'empty'
        for line in html_lines:
            if self.now.strftime("%d/%m/%Y") in line or self.now.strftime(
                    "%d/%m") in line:
                logging.debug(line)
                logging.info('A podcast found for %s', \
                             self.now.strftime("%d-%m-%Y"))
                process_a = line.split('href=\"')
                for link in process_a:
                    if link.startswith("DefaultArthro"):
                        process_c = link.split('\">')
                        download_page = process_c[0]
                        podtitle = process_c[1][:-10].decode('utf-8')
        if download_page == 'empty':
            logging.info("No podcast found for: %s", \
                                             self.now.strftime("%d/%m/%Y"))
            logging.info("Exiting")
            sys.exit()
        else:
            return self.base_url + '/' + download_page
Пример #3
0
def main():
    logging.basicConfig(filename = 'podcast.log', \
                        format = '%(asctime)s %(message)s', level = logging.INFO)

    cmn = common.common_functions()
    chatz = chatzinikolaou.chatzinikolaou_functions()
    url_chatz = cmn.config_section_map("chatzinikolaou")['url']

    if chatz.chatz_is_file_downloaded() == False:
        cmn.ensure_directory_structure('chatzinikolaou')
        main_page_html = cmn.get_html_and_split_lines(url_chatz)
        chatz_download_url = chatz.find_actual_download_url(main_page_html)
        download_page_html = cmn.get_html_and_split_lines(chatz_download_url)
        cmn.download_all_available_files(download_page_html, 'chatzinikolaou')
        cmn.concat_files_and_move("chatzinikolaou")
        rssgen = rss_gen.RssGenerator()
        rssgen.createxml("chatzinikolaou")
        logging.info("New chatzinikolaou episode file found and podcast updated")
    else:
        logging.info("Exiting")

    ellin = ellinofreneia.ellinofreneia_functions()
    ellin_chatz = cmn.config_section_map("ellinofreneia")['url']

    if ellin.ellin_is_file_downloaded() == False:
        cmn.ensure_directory_structure('ellinofreneia')
        main_page_html = cmn.get_html_and_split_lines(ellin_chatz)
        ellin_download_url = ellin.find_actual_download_url(main_page_html)
        download_page_ellin_html = cmn.get_html_and_split_lines(ellin_download_url)
        cmn.download_all_available_files(download_page_ellin_html, 'ellinofreneia')
        cmn.concat_files_and_move("ellinofreneia")
        rssgen = rss_gen.RssGenerator()
        rssgen.createxml("ellinofreneia")
        logging.info("New ellinofreneia episode file found and podcast updated")
    else:
        logging.info("Exiting")
Пример #4
0
 def __init__(self):
     self.cmn = common.common_functions()
Пример #5
0
class RssGenerator:
    now = datetime.datetime.now()
    cmn = common.common_functions()
    base_directory = cmn.config_section_map("home")['base_dir']

    def __init__(self):
        self.cmn = common.common_functions()

    def formatDate(self, dt):
        """
        Returns the date in correct format for podcast
        """
        return dt.strftime("%a, %d %b %Y %H:%M:%S GMT")

    # get the item/@type based on file extension
    def getItemType(self, fileExtension):
        """
        Returns the media type of the podcast.
        Support for multiple podcast formats e.g. video, audio
        """
        if fileExtension == "aac":
            mediaType = "audio/mpeg"
        elif fileExtension == "mp4":
            mediaType = "video/mpeg"
        else:
            mediaType = "audio/mpeg"
            return mediaType

    def createxml(self, name):
        """
        Function for generating the xml podcast file
        """
        xml_dict = self.cmn.config_section_map(name)

        rssTitle = xml_dict['rss_title']

        rssDescription = xml_dict['rss_description']
        rssSiteURL = xml_dict['base_url']
        rssItemURL = xml_dict['podcast_dir_url']
        rssLink = rssSiteURL + xml_dict['podcast_location']
        rssImageUrl = xml_dict['image_url']
        rssTtl = "60"
        rssWebMaster = "*****@*****.**"
        now = datetime.datetime.now()
        rootdir = self.base_directory + name
        outputFilename = self.base_directory + xml_dict['xml_file']
        episode_title = xml_dict['episode_title']
        episode_desc = xml_dict['episode_desc']

        print "Updating : " + outputFilename

        # open rss file
        outputFile = open(outputFilename, "w")

        # write rss header
        outputFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
        outputFile.write("<rss version=\"2.0\">\n")
        outputFile.write("<channel>\n")
        outputFile.write("<title>" + rssTitle + "</title>\n")
        outputFile.write("<description>" + rssDescription + "</description>\n")
        outputFile.write("<link>" + rssLink + "</link>\n")
        outputFile.write("<ttl>" + rssTtl + "</ttl>\n")
        outputFile.write("<image><url>" + rssImageUrl + "</url><title>"\
                          + rssTitle + "</title><link>" \
                          + rssLink + "</link></image>\n")
        outputFile.write("<copyright>mart 2012</copyright>\n")
        outputFile.write("<lastBuildDate>" + self.formatDate(now) \
                         + "</lastBuildDate>\n")
        outputFile.write("<pubDate>" + self.formatDate(now) + "</pubDate>\n")
        outputFile.write("<webMaster>" + rssWebMaster + "</webMaster>\n")

        for fileName in os.listdir(self.base_directory + name):
            logging.debug("fileName: " + fileName)
            fileNameBits = fileName.split(".")
            logging.debug(fileNameBits)
            if len(fileNameBits) == 2:
                if fileNameBits[1] != "xml":
                    logging.info("Creating xml entry for: %s", fileNameBits[0])
                    path = os.path.join(os.getcwd() + '/' + name)
                    fullPath = os.path.join(path, fileName)
                    logging.debug("fullpath is: %s", fullPath)
                    # get the stats for the file
                    fileStat = os.stat(fullPath)
                    # find the path relative to the starting folder, e.g. /subFolder/file
                    relativePath = fullPath[len(rootdir):]
                    audio_length = self.cmn.get_podcast_duration(fullPath)
                    logging.info("Duration for %s is %s", \
                                  fileName, audio_length)
                    filedate = fileNameBits[0].split("_")
                    # write rss item
                    outputFile.write("<item>\n")
                    outputFile.write("<title>" + filedate[1][0:2] \
                        + "/" + filedate[1][2:4]\
                        + "/" + filedate[1][6:8]
                        + " " + episode_title + "</title>\n")
                    outputFile.write("<description>" + episode_desc\
                                      + "</description>\n")
                    outputFile.write("<link>" + rssItemURL + relativePath\
                                      + "</link>\n")
                    outputFile.write("<guid>" + rssItemURL + relativePath\
                                      + "</guid>\n")
                    outputFile.write("<pubDate>"\
                        + self.formatDate(\
                        datetime.datetime.fromtimestamp(fileStat[ST_MTIME]))\
                                      + "</pubDate>\n")
                    outputFile.write("<duration>" + audio_length\
                                      + "</duration>\n")
                    outputFile.write("<enclosure url=\"" + rssItemURL\
                                      + relativePath + "\" length=\""\
                                      + str(fileStat[ST_SIZE]) + "\" type=\""\
                                      + self.getItemType(\
                                       fileNameBits[len(fileNameBits) - 1])\
                                      + "\" />\n")
                    outputFile.write("</item>\n")

        outputFile.write("</channel>\n")
        outputFile.write("</rss>")
        outputFile.close()
        print "Operation completed"
        logging.info("Podacast xml updated.")
Пример #6
0
 def __init__(self):
     self.cmn = common.common_functions()