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