#!/usr/bin/env python
import re
try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen


urldir = u"http://ftpmirror.gnu.org/gcc/"

dlpage = urlopen(urldir).read().decode("utf-8")
versions = re.findall(u"gcc-([0-9][0-9.]*[0-9])", dlpage)

versions.sort(key=lambda v: [int(n) for n in v.split(u".")])
version = versions[-1]

url = urldir + "gcc-{version}/gcc-{version}.tar.xz".format(version=version)

print(url)
