Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python3
from io import BytesIO
import json
import os
from sys import argv
import tarfile
from urllib.request import urlopen
def get_bytes(url):
return urlopen(url).read()
def get_str(url):
return get_bytes(url).decode()
def get_index(chan):
return json.loads(get_bytes("https://nodejs.org/download/{0}/index.json".format(chan)))
def get_linux_x64_ver(idx):
for item in idx:
if "linux-x64" in item["files"]:
return item["version"]
def get_linux_x64_url(chan, ver):
return "https://nodejs.org/download/{0}/{1}/node-{1}-linux-x64.tar.xz".format(chan, ver)
def get_linux_x64_bytes(chan, ver):
return get_bytes(get_linux_x64_url(chan, ver))
def get_linux_x64_tar(chan, ver):
return tarfile.open(mode="r:xz", fileobj=BytesIO(get_linux_x64_bytes(chan, ver)))
def extract_linux_x64_tar(chan, ver, path):
get_linux_x64_tar(chan, ver).extractall(path=path)
if __name__ == "__main__":
chan = argv[1]
ver = get_linux_x64_ver(get_index(chan))
extract_linux_x64_tar(chan, ver, os.getcwd())
print("node-{0}-linux-x64".format(ver), end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment