Exemplo n.º 1
0
def updatePodcastXML(url):
    #First get the podcasts name
    name = fileUtil.getPodcastName(url)  #Gets the name from the url
    if (name == None):  #Checks if it has found no name
        print("Error - Podcast has no name...")  #If so this is an error
        return
    name = fileUtil.cleanForWindows(
        name)  #Removes any characters from a name that are invalid in linux
    #Downloading the rss file
    rssFilepath = Path(".rss/" + name)
    print("\nDownloading rss file for: " + name)
    success = webUtil.downloadFileStream(url, rssFilepath,
                                         0)  #Downloads the rss file
    if (success == False):
        print("Error in updating podcast")
        return
    else:
        print("Checking for new episodes")
    urls = fileUtil.getEnclosedLinks(
        str(rssFilepath))  #Gets the enclosed links and titles from the file
    #Check for a folder
    podcastFolderExists = fileUtil.checkDir(name)
    if (not (podcastFolderExists)):
        os.mkdir(name)
    #Run the urls (episodes)
    for url in urls:
        filePathSansType = Path(
            name + "/" +
            url[0])  #Generates the filepath for where the new file will go
        fileAlreadyExists = fileUtil.checkFileSansType(
            filePathSansType)  #Checks to see if the file is already downloaded
        if (not (fileAlreadyExists)):  #If not
            filetype = webUtil.getFileType(
                url[1])  #Gets the filetype of the file the url points to
            if (filetype == None):  #If the filetypes is not found correctly
                print("Error Downloading file")  #Error message
                continue  #Try next file
            filePath = Path(
                name + "/" + url[0] + filetype
            )  #Create the filepath where the file will be downloaded to
            print("Fetching new file: " + url[0])
            success = webUtil.downloadFileStream(
                url[1], filePath,
                0)  #Download the file to the correct location
            if (success == None):
                print("Error - File not downloaded")
Exemplo n.º 2
0
#Licence Notice
print(
    "Bean Scraper  Copyright (C) 2019-2020  Martin Lewis\nThis program comes with ABSOLUTELY NO WARRANTY; for details type \'w\'"
)
print(
    "This is free software, and you are welcome to redistribute it under certain conditions; type \'c\' for details.\n"
)
time.sleep(1)
print("Starting Bean Scraper")  #Welcome Line

#Start up operations before start
#Data structure and variable creation
feeds = updateFeeds()

#Rss folder
feedsFolderExists = fileUtil.checkDir(".rss")  #Checks if the folder exists
if (not (feedsFolderExists)):  #If not creates it
    print("Making folder")
    os.mkdir(".rss")

#Main program loop
while True:
    print("Please select an option")
    selected = False
    while not (selected):
        print(
            "1 - Update Podcasts\n2 - Add a Podcast\n3 - Remove a Podcast\n4 - Show current Podcasts\nQ - Quit"
        )
        response = input("Select an option\n")
        if (response == "1"):
            for feed in feeds: