• pat31700

    To send any file to Pythonista, select sahre and "Run Pythonista Script"

    Then use this script below in Pythonista (you need to add it as an extension) to save any file from "run Pythonista Script" share method ... works with any file type .py .zip etc.

    All imported file are store in a directory "inbox" in Pythonista

    # coding: utf-8
    
    import appex
    import clipboard
    import console
    import shutil
    import os
    
    def getuniquename(filename, ext):
        root, extension = os.path.splitext(filename)
        if ext!='':
            extension = ext
        filename = root + extension
        filenum = 1
        while os.path.isfile(filename):
            filename = '{} {}{}'.format(root, filenum, extension)
            filenum += 1
        return filename
    
    def main():
        console.clear()
        dest_path_short = '~/Documents/inbox'
        dest_path = os.path.expanduser(dest_path_short)
        if not os.path.isdir(dest_path):
            print('Create ' + dest_path_short)
            os.mkdir(dest_path) 
        if not appex.is_running_extension():
            print('Using clipboard content...')
            text = clipboard.get()
            assert text, 'No text on the clipboard!'
            resp = console.alert('Alert!', 'Choose File Extension', '.py', '.pyui', hide_cancel_button=False)
            if resp==1:
                ext = '.py'
            elif resp==2:
                ext = '.pyui'
            filename=os.path.join(dest_path,'clipboard')
            filename=getuniquename(filename,ext)
            while os.path.isfile(filename):
                filename = '{} {}{}'.format(root, filenum, extension)
                filenum += 1
            with open(filename,'w') as f:
                f.write(text)
            print('Done!')      
        else:
            file = appex.get_file_path()    
            print('Input path: %s' % file)
            filename=os.path.join(dest_path, os.path.basename(file))
            filename=getuniquename(filename,'')
            shutil.copy(file,filename)
        print('Saved in %s' % dest_path_short)
        if not os.path.exists(filename):
            print(' > Error file %s not found !' % os.path.basename(filename))
        else:
            print(' > as %s' % os.path.basename(filename))
    
    if __name__ == '__main__':
        main()
    
    

    posted in Pythonista read more
  • pat31700

    Use "File Transfer" app to transfer file between devices.
    To send a script to "File Transfer" from Pythonista use "Share" and "Open In" to import in File transfer.
    To open a script from "File Transfer" to Pythonista, use "To other app" in "File Transfer" and on the bottom list select "Run Pythonista Script"

    Then use this script in Pythonista to save any file from the previous "run Pythonista Script"

    # coding: utf-8
    
    import appex
    import clipboard
    import console
    import shutil
    import os
    
    def getuniquename(filename, ext):
        root, extension = os.path.splitext(filename)
        if ext!='':
            extension = ext
        filename = root + extension
        filenum = 1
        while os.path.isfile(filename):
            filename = '{} {}{}'.format(root, filenum, extension)
            filenum += 1
        return filename
    
    def main():
        console.clear()
        dest_path_short = '~/Documents/inbox'
        dest_path = os.path.expanduser(dest_path_short)
        if not os.path.isdir(dest_path):
            print('Create ' + dest_path_short)
            os.mkdir(dest_path) 
        if not appex.is_running_extension():
            print('Using clipboard content...')
            text = clipboard.get()
            assert text, 'No text on the clipboard!'
            resp = console.alert('Alert!', 'Choose File Extension', '.py', '.pyui', hide_cancel_button=False)
            if resp==1:
                ext = '.py'
            elif resp==2:
                ext = '.pyui'
            filename=os.path.join(dest_path,'clipboard')
            filename=getuniquename(filename,ext)
            while os.path.isfile(filename):
                filename = '{} {}{}'.format(root, filenum, extension)
                filenum += 1
            with open(filename,'w') as f:
                f.write(text)
            print('Done!')      
        else:
            file = appex.get_file_path()    
            print('Input path: %s' % file)
            filename=os.path.join(dest_path, os.path.basename(file))
            filename=getuniquename(filename,'')
            shutil.copy(file,filename)
        print('Saved in %s' % dest_path_short)
        if not os.path.exists(filename):
            print(' > Error file %s not found !' % os.path.basename(filename))
        else:
            print(' > as %s' % os.path.basename(filename))
    
    if __name__ == '__main__':
        main()
    
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!