Created
December 13, 2017 02:50
-
-
Save sko00o/2c0b5b4b30a1bd93f6a6b637c5ce6983 to your computer and use it in GitHub Desktop.
ImportFile.py
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
# -*- coding: utf-8 -*- | |
# Author: SKo00o | |
''' | |
Use for import script file to pythonista. | |
Add this script in pythonsta’s Share Extention Shortcuts. | |
''' | |
import appex | |
import os | |
import console | |
if __name__ == '__main__': | |
save_dir = '/private/var/mobile/Containers/Shared/AppGroup/'+ | |
'30C67772-D4CD-48E4-AFE2-F676A1B26FF8/Pythonista3/Documents' | |
# May be your path is different. I haven't test on other device. | |
os.chdir(save_dir) | |
file = appex.get_file_path() | |
infile = open(file, 'rb') | |
Filename = infile.name.split('/')[-1] | |
NewFilename = Filename | |
while(os.listdir().__contains__(NewFilename)): | |
NewFilename = 'N_' + NewFilename | |
NewFilename = str(console.input_alert( | |
'Filename Exist!', 'New Filename?', NewFilename)) | |
outfile = open(NewFilename, 'wb') | |
outfile.write(infile.read()) | |
infile.close() | |
outfile.close() | |
console.alert('Done', 'File Accepted!', 'OK', hide_cancel_button=True) | |
appex.finish() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment