I would like to download a single file from a GitHub repository. In bash, you could do something like this:
curl -kLSs "https://github.com/mikolalysenko/lena/archive/master.tar.gz" | tar xz --wildcards '*lena.png' --strip-components=1`
to download and save this file in the current working directory. How would one do this using only Python (aka. not calling a bash command)?
>Solution :
I am not sure if with "pure python" you mean without modules, if not using the method urlretrive from the urllib module could be a solution:
import urllib.request
def main():
urllib.request.urlretrieve("https://raw.githubusercontent.com/mikolalysenko/lena/master/lena.png", "test.png")
if __name__ == "__main__":
main()
To download files from github you have to use the raw.githubusercontent.com domain, because the files of github repositories get stored there, but this answer explains it better.