view fetch_latest_pangolearn.py @ 4:42126b414951 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pangolin commit ab174c9f8cbfc741501068dfa4f6ccf229a54489"
author iuc
date Thu, 03 Jun 2021 06:38:26 +0000
parents f557122d379e
children 437e28791761
line wrap: on
line source

#!/usr/bin/env python

import json
import os
import tarfile

# rely on the fact that pangolin itself uses the requests module
import requests

response = requests.get(
    "https://api.github.com/repos/cov-lineages/pangoLEARN/releases/latest"
)
if response.status_code == 200:
    details = json.loads(response.text)
    response = requests.get(details["tarball_url"])
    if response.status_code == 200:
        with open("pangolearn.tgz", "wb") as handle:
            handle.write(response.content)
        tf = tarfile.open("pangolearn.tgz")
        pl_path = tf.next().name
        tf.extractall()
        tf.close()
        os.rename(os.path.join(pl_path, "pangoLEARN"), "datadir")
    else:
        response.raise_for_status()
else:
    response.raise_for_status()