update-feed.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python3
  2. import datetime
  3. import io
  4. import json
  5. import textwrap
  6. atom_template = textwrap.dedent("""\
  7. <?xml version="1.0" encoding="utf-8"?>
  8. <feed xmlns="http://www.w3.org/2005/Atom">
  9. <title>youtube-dl releases</title>
  10. <id>https://yt-dl.org/feed/youtube-dl-updates-feed</id>
  11. <updated>@TIMESTAMP@</updated>
  12. @ENTRIES@
  13. </feed>""")
  14. entry_template = textwrap.dedent("""
  15. <entry>
  16. <id>https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@</id>
  17. <title>New version @VERSION@</title>
  18. <link href="http://rg3.github.io/youtube-dl" />
  19. <content type="xhtml">
  20. <div xmlns="http://www.w3.org/1999/xhtml">
  21. Downloads available at <a href="https://yt-dl.org/downloads/@VERSION@/">https://yt-dl.org/downloads/@VERSION@/</a>
  22. </div>
  23. </content>
  24. <author>
  25. <name>The youtube-dl maintainers</name>
  26. </author>
  27. <updated>@TIMESTAMP@</updated>
  28. </entry>
  29. """)
  30. now = datetime.datetime.now()
  31. now_iso = now.isoformat() + 'Z'
  32. atom_template = atom_template.replace('@TIMESTAMP@', now_iso)
  33. versions_info = json.load(open('update/versions.json'))
  34. versions = list(versions_info['versions'].keys())
  35. versions.sort()
  36. entries = []
  37. for v in versions:
  38. entry = entry_template.replace('@TIMESTAMP@', v.replace('.', '-') + 'T00:00:00Z')
  39. entry = entry.replace('@VERSION@', v)
  40. entries.append(entry)
  41. entries_str = textwrap.indent(''.join(entries), '\t')
  42. atom_template = atom_template.replace('@ENTRIES@', entries_str)
  43. with io.open('update/releases.atom', 'w', encoding='utf-8') as atom_file:
  44. atom_file.write(atom_template)