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