Read content of file which is in Github using pyGithub?

Let say "sample.txt" file is in GitHub under "Demo" repo [Demo/sample.txt], how can I read the content of sample.txt using pyGithub instead fetching from API ? Else do we have someother package to read such file content ?

Answers

You can use this code for see the content of the file:

from github import Github
github = Github('user', 'password')
user = github.get_user()
repository = user.get_repo('Demo')
file_content = repository.get_contents('sample.txt')
print(file_content.decoded_content.decode())

if you need see more atributes like decoded_content just type this:

print(help(file_content))

And sorry for me english, I'm bad.

Posted on by Anonymous