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