Snippets Collections
import feedparser
import requests
import pathlib

# Set the path to the folder
folder_path = pathlib.Path("C:/Python311/OARscripts/Experiments/BlowingBubbles")

# Delete existing files in the folder
for file in folder_path.glob("*"):
    try:
        file.unlink()
    except Exception as e:
        print(f"Error deleting {file}: {e}")

# Download latest episode
url = "https://feeds.accessmedia.nz/V2/itunes/95444842-39c8-4d47-b4c6-4a0fd697e569"
feed = feedparser.parse(url)
latest_entry = feed.entries[0]
file_url = latest_entry.enclosures[0].url
destination_folder = folder_path
file_name = pathlib.Path(file_url).name
new_file_name = "new_file_name.mp3"

try:
    # Download the file
    response = requests.get(file_url)
    with open(destination_folder / file_name, "wb") as f:
        f.write(response.content)

    # Rename the file
    (destination_folder / file_name).rename(destination_folder / new_file_name)

    print(f"File downloaded to {destination_folder / new_file_name}")
except Exception as e:
    print(f"Error downloading or renaming file: {e}")

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension