update-feed.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. <atom:feed xmlns:atom="http://www.w3.org/2005/Atom">
  9. <atom:title>youtube-dl releases</atom:title>
  10. <atom:id>https://yt-dl.org/feed/youtube-dl-updates-feed</atom:id>
  11. <atom:updated>@TIMESTAMP@</atom:updated>
  12. @ENTRIES@
  13. </atom:feed>""")
  14. entry_template = textwrap.dedent("""
  15. <atom:entry>
  16. <atom:id>https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@</atom:id>
  17. <atom:title>New version @VERSION@</atom:title>
  18. <atom:link href="http://rg3.github.io/youtube-dl" />
  19. <atom: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. </atom:content>
  24. <atom:author>
  25. <atom:name>The youtube-dl maintainers</atom:name>
  26. </atom:author>
  27. <atom:updated>@TIMESTAMP@</atom:updated>
  28. </atom:entry>
  29. """)
  30. now = datetime.datetime.now()
  31. now_iso = now.isoformat()
  32. atom_template = atom_template.replace('@TIMESTAMP@', now_iso)
  33. entries=[]
  34. versions_info = json.load(open('update/versions.json'))
  35. versions = list(versions_info['versions'].keys())
  36. versions.sort()
  37. for v in versions:
  38. entry = entry_template.replace('@TIMESTAMP@',v.replace('.','-'))
  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)