Skip to content

Instantly share code, notes, and snippets.

@ThinkCode
Forked from omz/PythonistaBackup.py
Created February 7, 2016 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThinkCode/079737ee4b2613b9f348 to your computer and use it in GitHub Desktop.
Save ThinkCode/079737ee4b2613b9f348 to your computer and use it in GitHub Desktop.
PythonistaBackup.py
# coding: utf-8
'''Creates a zip archive of your Pythonista files and serves them via HTTP in your local network.'''
from SimpleHTTPServer import SimpleHTTPRequestHandler
import os
import shutil
import tempfile
import shutil
PORT = 8080
if __name__ == '__main__':
doc_path = os.path.expanduser('~/Documents')
os.chdir(doc_path)
backup_path = os.path.join(doc_path, 'Backup.zip')
if os.path.exists(backup_path):
os.remove(backup_path)
print 'Creating backup archive...'
shutil.make_archive(os.path.join(tempfile.gettempdir(), 'Backup'), 'zip')
shutil.move(os.path.join(tempfile.gettempdir(), 'Backup.zip'), backup_path)
print 'Backup archive created, starting HTTP server...'
from BaseHTTPServer import HTTPServer
server = HTTPServer(('', PORT), SimpleHTTPRequestHandler)
print 'You can now download a backup of your Pythonista scripts by entering this URL in Safari (on this device):'
print 'http://localhost:%i/Backup.zip' % (PORT,)
print 'If you want to download the backup to another device in your network, use your device\'s IP address instead of "localhost".'
print 'Tap the stop button in the editor or console when you\'re done.'
try:
server.serve_forever()
except KeyboardInterrupt:
server.shutdown()
print 'Server stopped'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment