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


js = json.load(urlopen(u"https://api.github.com/repos/numpy/numpy/git/refs/tags"))

versions = []
for item in js:
    m = re.match(u"^refs/tags/v([0-9][0-9.]*[0-9])$", item["ref"])
    if m:
        versions.append(m.group(1))

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

url = "https://github.com/numpy/numpy/releases/download/v{version}/numpy-{version}.tar.gz".format(version=version)

print(url)
