-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathget_versions.py
More file actions
44 lines (33 loc) · 1.38 KB
/
get_versions.py
File metadata and controls
44 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import re
import requests
from bs4 import BeautifulSoup
reversion = re.compile(r'\d+\.\d+(?:\.\d+)?/$')
def main():
downloads = requests.get('https://www.python.org/downloads/')
downloads.raise_for_status()
wanted = []
soup = BeautifulSoup(downloads.content, 'html.parser')
version_rows = soup.find('div', class_='active-release-list-widget').find('ol', class_='list-row-container')
for row in version_rows.find_all('li'):
branch = row.find('span', class_='release-version').text
status = row.find('span', class_='release-status').text
if status in ('bugfix', 'security'):
wanted.append(tuple(map(int, branch.split('.'))))
ftp = requests.get('https://www.python.org/ftp/python/')
ftp.raise_for_status()
soup = BeautifulSoup(ftp.content, 'html.parser')
releases = {}
for version in soup.find_all('a'):
href = version['href']
if reversion.match(href):
release = tuple(map(int, href.rstrip('/').split('.')))
branch = (release[0], release[1])
if branch in wanted:
if branch in releases:
releases[branch] = max(releases[branch], release)
else:
releases[branch] = release
for _, release in sorted(releases.items()):
print('.'.join(map(str, release)))
if __name__ == '__main__':
main()