I have an existing README.md file in a github repository. How can I update the README.md file through a python script using github API? I guess the API states that we can get contents for a file. I want to know how do I add markdown text to the content, overwrite the README.md file and add it to the repository as a commit from within the python script using the API.
1 Answer
Use the PyGitHub module, which is a python wrapper for the GitHub api.
from github import Github
# Authenticate yourself
g = Github("yourusername", "yourauthtoken")
# Find your repository and path of README.md
repo=g.get_user().get_repo("your repo")
file = repo.get_contents("README.md")
# The new contents of your README.md
content = "your updated README file contents"
# Update README.md
repo.update_file("README.md", "commit message", content, file.sha)
1 Comment
ragethewolf
Won't this replace the existing data with new data is there a way to append the new data and not impact the existing data.