MaverickTse / pyMingwBuild

Python(Anaconda) script to build Mingw-w64 cross-toolchain
MIT License
1 stars 1 forks source link

[proposal]use github api #1

Open yumetodo opened 7 years ago

yumetodo commented 7 years ago

Extracting url with regex hack is dirty. Why don't you use Github API?

import json
from urllib import request, response
j = json.loads(request.urlopen("https://api.github.com/repos/mirror/mingw-w64/tags").read().decode())

final_url = j[1]

# Search latest version except rc
for i, o in enumerate(j):
    if not "rc" in o["name"]:
        final_url = o["tarball_url"]
        break

# Search for preferred version
for i, o in enumerate(j):
    if o["name"] == preferred_version:
        final_url = o["tarball_url"]
        break
MaverickTse commented 7 years ago

Initially I intent to write a general HTML scraper and downloader. Only when I later discovered MPFR, GMP, etc. also hosted on the same server as GCC, I moved them to use FTP download function, leaving a single component for HTML(GitHub) download.

If you are willing to, you can implement a NEW function with similar function signature as the existing HTML download function and replace the calls to it. However, DO NOT REMOVE the original function as that MAY BE useful in the future (in case things move to other webpage or sourceforge)