Last active
August 4, 2017 06:54
-
-
Save Au1st3in/a76ee561fbfb4785d3c53f559563852f to your computer and use it in GitHub Desktop.
Air for Steam Skin Updater
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 io, os, re, requests, shutil, sys, wget, zipfile | |
def copydir(source, dest, indent=0): | |
for root, dirs, files in os.walk(source): | |
if not os.path.isdir(root): | |
os.makedirs(root) | |
for each_file in files: | |
rel_path = root.replace(source, '').lstrip(os.sep) | |
dest_path = os.path.join(dest, rel_path, each_file) | |
shutil.copyfile(os.path.join(root, each_file), dest_path) | |
if __name__ == "__main__": | |
try: | |
config = {} | |
try: | |
with open('config.ini') as ini: | |
for line in ini: | |
if (not '//' in line or ('" //' in line and line.count('//') == 1)) and 'include' in line: | |
property, selection = re.search('resource/(.*)s/', line), re.search('s/(.*).styles', line) | |
config[property.group(1)] = selection.group(1).strip('_') | |
except IOError: | |
wget.download('https://raw.githubusercontent.com/Outsetini/Air-for-Steam/master/config.ini') | |
sys.exit(1) | |
releases = requests.get('https://api.github.com/repos/Outsetini/Air-for-Steam/releases') | |
latest = releases.json()[0] | |
try: | |
with open('version.txt', 'r') as version: | |
config['version'] = version.read().replace('\n', ':') | |
if config['version'].split(':')[1] == latest['tag_name'] and config['version'].split(':')[0] == config['theme'].lower(): | |
sys.exit(0) | |
except IOError: | |
pass | |
for rem in [d for d in os.listdir(os.curdir) if not d in {'config.ini', os.path.basename(__file__)}]: | |
if '.' in rem: | |
os.remove(rem) | |
else: | |
shutil.rmtree(rem) | |
with open('version.txt', 'w') as version: | |
version.write(config['theme'].lower()+':'+latest['tag_name']) | |
request = requests.get(latest['zipball_url']) | |
zip = zipfile.ZipFile(io.BytesIO(request.content)) | |
zip.extractall() | |
config['zip'] = [f for f in os.listdir(os.curdir) if not f in {'config.ini', 'version.txt', os.path.basename(__file__)}][0] | |
copydir('./'+config['zip']+'/+Extras/Themes/'+config['theme'].title(), './'+config['zip']) | |
copydir('./'+config['zip']+'/+Extras/Square Avatars/'+config['theme'].title(), './'+config['zip']+'/Graphics') | |
shutil.rmtree('./'+config['zip']+'/+Extras') | |
for folder in [dir for dir in os.listdir('./'+config['zip']) if not '.' in dir]: | |
shutil.copytree('./'+config['zip']+'/'+folder, './'+folder) | |
shutil.rmtree('./'+config['zip']) | |
sys.exit(0) | |
except: | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment