File size: 824 Bytes
ef63ede
5e8e534
ef63ede
5e8e534
 
ef63ede
ba7ddeb
5e8e534
 
ef63ede
 
 
5e8e534
ef63ede
5e8e534
 
 
ef63ede
5e8e534
 
 
 
 
 
1bd0d83
5e8e534
ef63ede
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time

import requests
from omegaconf import OmegaConf


def gh_download(repo, path):
    paths = [path] if isinstance(path, str) else path
    result = None
    headers = {
        "Accept": "application/vnd.github.raw+json",
    }
    for path in paths:
        url = f"https://api.github.com/repos/{repo}/contents/{path}"
        response = requests.get(url, headers=headers)
        if response.status_code != 200:
            raise Exception(f"Failed to download {path} from {repo}")

        if result is None:
            result = response.json()
        elif isinstance(result, list):
            result.extend(response.json())
        elif isinstance(result, dict):
            result.update(response.json())
    time.sleep(0.1)
    return result


OmegaConf.register_new_resolver("gh_download", gh_download)