Created
February 21, 2016 07:08
-
-
Save dzhu/e847209df4325d9af0dd to your computer and use it in GitHub Desktop.
python Screeps push script
This file contains 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 hashlib | |
import json | |
import glob | |
import os | |
import requests | |
auth = ('EMAIL', 'PASSWORD') | |
def push(ptr=False): | |
URL = 'https://screeps.com/ptr/api/user/code' if ptr else 'https://screeps.com/api/user/code' | |
j = { | |
'branch': 'default', | |
'modules': {}, | |
} | |
for fn in glob.glob('*.js'): | |
j['modules'][fn[:-3]] = open(fn).read() | |
if ptr: | |
j['modules']['main_real'] = j['modules']['main'] | |
j['modules']['main'] = j['modules']['ptr'] | |
hashes = '{%s}' % ', '.join('%s: "%s"' % (k, hashlib.md5(v).hexdigest()) for k, v in j['modules'].iteritems()) | |
j['modules']['main'] = j['modules']['main'].replace("'__HASHES__'", hashes) | |
r = requests.post(URL, | |
auth=auth, data=json.dumps(j), | |
headers={'Content-Type': 'application/json; charset=utf-8'}) | |
print r.content | |
print r.status_code | |
if __name__ == '__main__': | |
import sys | |
push(len(sys.argv) > 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment