Last active
October 3, 2021 03:55
-
-
Save pingiun/ede110c5754b1fae0c33ed0bc6e32252 to your computer and use it in GitHub Desktop.
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
import re | |
import sys | |
from datetime import datetime | |
from b2.api import B2Api | |
def parse(inp, mformat=None, thing=None): | |
if thing is None: | |
thing = 'th' | |
if mformat is None: | |
mformat = '%B' | |
try: | |
return datetime.strptime(inp, '{} %d{}, %Y'.format(mformat, thing)) | |
except ValueError: | |
if thing == 'nd': | |
return parse(inp, thing='st', mformat=mformat) | |
if thing == 'st': | |
return parse(inp, thing='rd', mformat=mformat) | |
if thing == 'rd': | |
return parse(inp, thing='', mformat=mformat) | |
if thing == '': | |
if mformat == '%b': | |
return None | |
return parse(inp, mformat='%b') | |
return parse(inp, thing='nd', mformat=mformat) | |
api = B2Api() | |
raw_api = api.raw_api | |
if not api.authorize_automatically(): | |
print("Error authorizing with backblaze") | |
sys.exit(1) | |
api_url = api.account_info.get_api_url() | |
account_auth_token = api.account_info.get_account_auth_token() | |
bucket_id = '6456b1bdab36bc5567290d1a' | |
response = raw_api.list_file_names(api_url, account_auth_token, bucket_id) | |
files = response['files'] | |
next_file_name = response['nextFileName'] | |
print('<?xml version="1.0" encoding="UTF-8"?>') | |
print('<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">') | |
print("""<channel> | |
<title>The Northernlion Live Super Show!</title> | |
<link>https://www.youtube.com/playlist?list=PL1bauNEiHIgwFwmzhBO9ng8ma2WsLUzBh</link> | |
<lastBuildDate>{}</lastBuildDate> | |
<language>en-US</language> | |
<generator>Python script by pingiun</generator> | |
<itunes:author>Northernlion</itunes:author> | |
<itunes:subtitle>The Northernlion Live Super Show!</itunes:subtitle> | |
<itunes:summary>The Northernlion Live Super Show!</itunes:summary> | |
<description>The Northernlion Live Super Show!</description> | |
<itunes:explicit>no</itunes:explicit>""".format(datetime.now().strftime("%a, %d %b %Y %H:%M:%S +0100"))) | |
for file in files: | |
url = api.get_download_url_for_fileid(file['fileId']) | |
match = re.match(r'The Northernlion Live Super Show!? \[ ?(.*?)\](.*)?', file['fileName']) | |
print('<item>') | |
print('<title>{}</title>'.format(file['fileName'].split('.')[0])) | |
print('<description>{}</description>'.format(file['fileName'].split('.')[0])) | |
print('<pubDate>{}</pubDate>'.format(parse(match.group(1)).strftime('%a, %d %b %Y %H:%M:%S +0100'))) | |
print('<enclosure url="{}" length="{}" type="audio/mpeg" />'.format(url, file['contentLength'])) | |
print('</item>') | |
print('</channel>') | |
print('</rss>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment