Last active
October 27, 2015 18:21
-
-
Save brianddk/c0eaaedc339a50a71fb5 to your computer and use it in GitHub Desktop.
Zip the last MCPE savegame
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
| #!/usr/bin/env python2 | |
| #-*-coding:utf8;-*- | |
| #qpy:2 | |
| #qpy:kivy | |
| from __future__ import print_function | |
| import os | |
| import sys | |
| import zipfile | |
| if 'qpyplus' in os.__file__: | |
| rootdir = os.sep | |
| else: | |
| rootdir = '.' | |
| gamedir = os.path.join(rootdir, 'sdcard', 'games', 'com.mojang') | |
| worlds = os.path.join(gamedir, 'minecraftWorlds') | |
| backup = os.path.join(worlds, 'backups') | |
| option = os.path.join(gamedir + 'minecraftpe') | |
| def findlast_save(worlds): | |
| latest = 0 | |
| lastsave = '' | |
| for root, dirs, files in os.walk(worlds): | |
| for file in files: | |
| if file.endswith('level.dat'): | |
| mtime = os.path.getmtime(os.path.join(root, file)) | |
| if mtime > latest: | |
| lastsave = root | |
| latest = mtime | |
| return lastsave | |
| def read_savename(savedir): | |
| name_file = open(os.path.join(savedir, 'levelname.txt'), 'r') | |
| savename = name_file.readline() | |
| name_file.close() | |
| return savename | |
| def backup_save(savedir, zipname): | |
| zipname = os.path.abspath(zipname) | |
| root, dirname = os.path.split(savedir) | |
| os.chdir(root) | |
| zipf = zipfile.ZipFile(zipname, 'w') | |
| for root, dirs, files in os.walk(dirname): | |
| for file in files: | |
| zipf.write(os.path.join(root, file)) | |
| zipf.close() | |
| if __name__ == '__main__': | |
| for directory in [worlds, backup]: | |
| if not os.path.exists(directory): | |
| os.makedirs(directory) | |
| savedir = findlast_save(worlds) | |
| savename = read_savename(savedir) | |
| backup_save(savedir, os.path.join(backup, savename + '.zip')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment