Created
January 8, 2023 06:09
-
-
Save Chealion/e39a59ae487a7ce752a63d505c7872be to your computer and use it in GitHub Desktop.
Grabbing your starred episodes from the Overcast OPML data export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/env/python | |
| import xml.etree.ElementTree as ET | |
| from datetime import datetime | |
| import urllib.parse | |
| import webbrowser | |
| # Strongly recommend you run `grep userRecommendedDate overcast.opml | wc -l` to know how many entries you are about to make... | |
| # CHANGE BELOW AS NEED BE | |
| # Last run date will allow you to skip processing anything from before this date | |
| LAST_RUN_DATE=datetime.fromisoformat('2022-01-07') | |
| # Change overcast.opml to the file name | |
| tree = ET.parse('overcast.opml') | |
| starredEpisodes = tree.iterfind("./body/outline[@text='feeds']/outline/outline[@userRecommendedDate]") | |
| for episode in starredEpisodes: | |
| recommendDate = datetime.strptime(episode.attrib['userRecommendedDate'], '%Y-%m-%dT%H:%M:%S%z') | |
| if recommendDate.date() < LAST_RUN_DATE.date(): | |
| continue | |
| episodeTitle = episode.attrib['title'] | |
| overcastURL = episode.attrib['overcastUrl'] | |
| overcastID = episode.attrib['overcastId'] | |
| # Now we need to backtrack to the parent xml to get: | |
| # htmlURL = episode URL | |
| # title = episode Name | |
| podcast = tree.find("./body/outline[@text='feeds']/outline/outline[@overcastId='%s']/.." % overcastID) | |
| podcastTitle = podcast.attrib['title'] | |
| podcastURL = '' | |
| if episode.attrib['url']: | |
| podcastURL = episode.attrib['url'] | |
| else: | |
| podcastURL = podcast.attrib['htmlUrl'] | |
| hyphenatedName = podcastTitle.replace(" ", "-").lower() | |
| # Construct the Text for Bear | |
| noteText = """ | |
| <Things I Liked> | |
| --- | |
| ###### %s - %s | |
| %s | |
| %s | |
| #draft #public #podcast #%s | |
| """ % (podcastTitle, episodeTitle, overcastURL, podcastURL, hyphenatedName) | |
| noteTitle = "%s - %s" % (podcastTitle, episodeTitle) | |
| bearURL = "bear://x-callback-url/create?title=%s&open_note=no&show_window=no&text=%s" % (urllib.parse.quote(noteTitle), urllib.parse.quote(noteText)) | |
| print(bearURL) | |
| webbrowser.open(bearURL, new=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment