Pygithub: How do I download a file?

Created on 10 Jan 2020  路  1Comment  路  Source: PyGithub/PyGithub

I am trying to download a file and so far have reached here, also looked at https://github.com/PyGithub/PyGithub/issues/661

I have reached here so far.

    repo = client.get_repo(GIT_REPO)
    contents = repo.get_contents(file_path, ref=GIT_BRANCH)
    print (contents)    # <-- ContentFile(path="clusters/poc2/test.txt")
    file_content = repo.get_contents(urllib.parse.quote(contents.path), ref=GIT_BRANCH)
    print (file_content)   # <-- ContentFile(path="clusters/poc2/test.txt")

I can use GitAPI to download a file, but just trying out my hands with this package :)

Most helpful comment

There are two methods, -- first, just use file_content.content which is the contents, which you can write to a file. Secondly, there's file_content.download_url to grab it.

>All comments

There are two methods, -- first, just use file_content.content which is the contents, which you can write to a file. Secondly, there's file_content.download_url to grab it.

Was this page helpful?
0 / 5 - 0 ratings