#!/usr/bin/env python3
import datetime
import io
import json
import textwrap
atom_template = textwrap.dedent("""\
youtube-dl releases
https://yt-dl.org/feed/youtube-dl-updates-feed
@TIMESTAMP@
@ENTRIES@
""")
entry_template = textwrap.dedent("""
https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@
New version @VERSION@
The youtube-dl maintainers
@TIMESTAMP@
""")
now = datetime.datetime.now()
now_iso = now.isoformat() + 'Z'
atom_template = atom_template.replace('@TIMESTAMP@', now_iso)
versions_info = json.load(open('update/versions.json'))
versions = list(versions_info['versions'].keys())
versions.sort()
entries = []
for v in versions:
entry = entry_template.replace('@TIMESTAMP@', v.replace('.', '-') + 'T00:00:00Z')
entry = entry.replace('@VERSION@', v)
entries.append(entry)
entries_str = textwrap.indent(''.join(entries), '\t')
atom_template = atom_template.replace('@ENTRIES@', entries_str)
with io.open('update/releases.atom', 'w', encoding='utf-8') as atom_file:
atom_file.write(atom_template)