Skip to content

Instantly share code, notes, and snippets.

@paulshannon
Last active July 27, 2016 15:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulshannon/ad61018f7cd5b0384968 to your computer and use it in GitHub Desktop.
Save paulshannon/ad61018f7cd5b0384968 to your computer and use it in GitHub Desktop.
Update Github from python
import datetime
import os
import subprocess
repo = "PaulShannon/TestRepo"
author = "PythonCronScript <>"
message = "Auto Updating"
def run(commands):
for c in commands:
r = subprocess.call(c)
print r, c
if r != 0:
exit()
directory = os.path.dirname(os.path.realpath(__file__))
repo_url = 'git@github.com:{}.git'.format(repo)
repo_path = os.path.join(directory, repo.split('/')[1])
filename = os.path.join(repo_path, 'README.md')
if os.path.isdir(repo_path):
os.chdir(repo_path)
run(["git pull -Xtheirs",])
else:
run(["git clone {} {}".format(repo_url, repo_path),])
os.chdir(repo_path)
with open(filename, 'a') as f:
f.write('\n- Updating @ ({})'.format(datetime.datetime.now().strftime('%c')))
run([
"git add {}".format(filename),
"git commit --author=\"{}\" -m \"{}\"".format(author, message),
"git push origin master",
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment