Reputation: 83
Let’s say "sample.txt" file is in GitHub under the "Demo" repository [Demo/sample.txt]. How can I read the content of sample.txt using PyGitHub instead fetching from the API?
Else, do we have some other package to read such file content?
Upvotes: 7
Views: 8230
Reputation: 306
You can use this code to 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 to see more attributes like decoded_content, just type this:
print(help(file_content))
Upvotes: 19
Reputation: 21275
You can use the get_contents
API
Here is an example:
from github import Github
github = Github('user', 'password')
user = github.get_user()
repository = user.get_repo('Demo')
file_content = repository.get_contents('sample.txt')
Upvotes: 0