]> Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/gh-pages/update-feed.py
Update upstream source from tag 'upstream/2020.09.14'
[youtubedl] / devscripts / gh-pages / update-feed.py
1 #!/usr/bin/env python3
2 from __future__ import unicode_literals
3
4 import datetime
5 import io
6 import json
7 import textwrap
8
9
10 atom_template = textwrap.dedent("""\
11 <?xml version="1.0" encoding="utf-8"?>
12 <feed xmlns="http://www.w3.org/2005/Atom">
13 <link rel="self" href="http://ytdl-org.github.io/youtube-dl/update/releases.atom" />
14 <title>youtube-dl releases</title>
15 <id>https://yt-dl.org/feed/youtube-dl-updates-feed</id>
16 <updated>@TIMESTAMP@</updated>
17 @ENTRIES@
18 </feed>""")
19
20 entry_template = textwrap.dedent("""
21 <entry>
22 <id>https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@</id>
23 <title>New version @VERSION@</title>
24 <link href="http://ytdl-org.github.io/youtube-dl" />
25 <content type="xhtml">
26 <div xmlns="http://www.w3.org/1999/xhtml">
27 Downloads available at <a href="https://yt-dl.org/downloads/@VERSION@/">https://yt-dl.org/downloads/@VERSION@/</a>
28 </div>
29 </content>
30 <author>
31 <name>The youtube-dl maintainers</name>
32 </author>
33 <updated>@TIMESTAMP@</updated>
34 </entry>
35 """)
36
37 now = datetime.datetime.now()
38 now_iso = now.isoformat() + 'Z'
39
40 atom_template = atom_template.replace('@TIMESTAMP@', now_iso)
41
42 versions_info = json.load(open('update/versions.json'))
43 versions = list(versions_info['versions'].keys())
44 versions.sort()
45
46 entries = []
47 for v in versions:
48 fields = v.split('.')
49 year, month, day = map(int, fields[:3])
50 faked = 0
51 patchlevel = 0
52 while True:
53 try:
54 datetime.date(year, month, day)
55 except ValueError:
56 day -= 1
57 faked += 1
58 assert day > 0
59 continue
60 break
61 if len(fields) >= 4:
62 try:
63 patchlevel = int(fields[3])
64 except ValueError:
65 patchlevel = 1
66 timestamp = '%04d-%02d-%02dT00:%02d:%02dZ' % (year, month, day, faked, patchlevel)
67
68 entry = entry_template.replace('@TIMESTAMP@', timestamp)
69 entry = entry.replace('@VERSION@', v)
70 entries.append(entry)
71
72 entries_str = textwrap.indent(''.join(entries), '\t')
73 atom_template = atom_template.replace('@ENTRIES@', entries_str)
74
75 with io.open('update/releases.atom', 'w', encoding='utf-8') as atom_file:
76 atom_file.write(atom_template)