Created
May 9, 2015 10:15
-
-
Save ScruffyRules/6528cb32912d2b4ff312 to your computer and use it in GitHub Desktop.
Auto Updates Phteven based on GitHub commit messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import zipfile | |
import os | |
import shutil | |
import json | |
import time | |
import sys | |
def unzip(source_filename, dest_dir): | |
with zipfile.ZipFile(source_filename) as zf: | |
zf.extractall(dest_dir) | |
def delete(filename): | |
if os.path.isfile(filename): | |
os.remove(filename) | |
if os.path.isdir(filename): | |
shutil.rmtree(filename) | |
def downloadFile(url) : | |
localFilename = url.split('/')[-1] | |
with open(localFilename, 'wb') as f: | |
start = time.clock() | |
r = requests.get(url, stream=True) | |
total_length = r.headers.get('content-length') | |
dl = 0 | |
lastnur = 0 | |
if total_length is None: | |
f.write(r.content) | |
else: | |
for chunk in r.iter_content(1024): | |
dl += len(chunk) | |
f.write(chunk) | |
done = int(100 * dl / int(total_length)) | |
if not done == lastnur: | |
sys.stdout.write("\r[%s%s] %s%%" % ('=' * done, ' ' * (100-done), done)) | |
lastnur = done | |
return (time.clock() - start) | |
def qPut(file, string): | |
with open(file, "w") as f: | |
f.write(string) | |
def qGet(file): | |
with open(file, "r") as f: | |
return f.read() | |
r = requests.get("https://api.github.com/repos/thinkofdeath/steven/commits") | |
print("5 Recent commits:") | |
jr = r.json() | |
print("\t" + jr[0]["commit"]["message"]) | |
print("\t" + jr[1]["commit"]["message"]) | |
print("\t" + jr[2]["commit"]["message"]) | |
print("\t" + jr[3]["commit"]["message"]) | |
print("\t" + jr[4]["commit"]["message"] + "\n") | |
if not qGet("commit") == jr[0]["commit"]["message"]: | |
qPut("commit", jr[0]["commit"]["message"]) | |
print("Downloading phteven zip") | |
timedone = downloadFile('http://ci.thinkofdeath.co.uk/guestAuth/repository/download/Steven_Client/.lastSuccessful/windows_amd64.zip') | |
print("\nDone! " + str(timedone)[:4] + "s\n") | |
print("Unzipping phteven zip") | |
unzip("windows_amd64.zip", ".") | |
print("Deleting phteven zip\n") | |
delete("windows_amd64.zip") | |
print("Running phteven!") | |
os.system("steven.exe") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment