• cvp

    @yutashx Is it not what you asked?

    posted in Pythonista read more
  • cvp

    @yutashx
    I'm really estonished but this script works as I hoped 😂

    # add a local video file to IOS photos
    from objc_util import *
    import threading
    
    PHPhotoLibrary = ObjCClass('PHPhotoLibrary')
    PHAssetChangeRequest = ObjCClass('PHAssetChangeRequest')
    
    def add_video():
        lib = PHPhotoLibrary.sharedPhotoLibrary()
        url = nsurl('IMG_6294.MOV')         # path to local video file
    
        def change_block():
            req = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL_(url)
            
        def perform_changes():
            lib.performChangesAndWait_error_(change_block, None)
            
        t = threading.Thread(target=perform_changes)
        t.start()
        t.join()
    
    if __name__ == '__main__':
        add_video() 
    

    posted in Pythonista read more
  • cvp

    @djorge You'll find hereafter my cleaned "import any file", it uses a File_Picker module of omz, you can find it here

    # coding: utf-8
    import appex
    import console
    import shutil
    import os
    import ui
    import File_Picker
    import unicodedata
    import urllib.request, urllib.parse, urllib.error
            
    def process():
        global my_back
            
        # called by sharing action or launcher
        if not appex.is_running_extension():
            return
    
        # Sharing: receive file to store in local folder
        fil = appex.get_file_path() 
        if fil == None:
            # no file shared
            url = appex.get_url()
    
            fil = urllib.request.urlopen(url)
    
            tot = fil.getheader('content-length')
    
            i = url.rfind('/') # index last /
            nam = url[i+1:] # right of last /
            
        
            block = 4096*1#6
            temp = os.path.join(os.path.expanduser("~"),'Documents/'+nam)   
            with open(temp, 'wb') as output:
                while True:
                    data = fil.read(block)
                    if data:
                        output.write(data)
                    else:
                        break   # leave loop
            fil = temp
            local_file = nam
    
        else:
            # file shared
            temp = None
            local_file = os.path.basename(fil)
        
        # Select folder where to move the file
        to_dir = File_Picker.file_picker_dialog('select folder where to copy', multiple=False, select_dirs=True, file_pattern=r'^.*\.py$')
        if to_dir != None:
            w = '/Pythonista3/Documents/'
            i = to_dir.find(w)
            dir_loc = to_dir
            if i >= 0:
                dir_loc = to_dir[i+len(w):] 
            else:
                dir_loc = ''
        else:
            if temp:
                os.remove(temp)
            return
    
        # Remove accents of file name
        local_file = ''.join((c for c in unicodedata.normalize('NFD', local_file) if unicodedata.category(c) != 'Mn'))  
        try:
            local_file = console.input_alert('Import file\n'+fil+'\nin',  dir_loc, local_file,'ok')
            import_file = True
        except KeyboardInterrupt:
            import_file = False
        if not import_file:
            if temp:
                os.remove(temp)
            return
        
        local_path = os.path.join(os.path.expanduser("~"),'Documents/'+dir_loc) 
        local_path = os.path.join(local_path,local_file)    
    
        shutil.copy(fil,local_path)
        if temp:
            os.remove(temp)
    
    def main():
        global my_back
    
        #----- Main code ------------------------
        console.clear()
        
        # Hide script
        #w, h = (540,620)
        my_back = ui.View(name='Import file')
        my_back.background_color='white'
        my_back.present('sheet',hide_title_bar=True)
        
        process()
        
        my_back.close()
        appex.finish()
        
    if __name__ == '__main__':
        main()
    

    posted in Pythonista read more
  • cvp

    @djorge Sorry but it's a copy of my own scripts icons.
    I'll clean my script and put a copy here.

    posted in Pythonista read more
  • cvp

    @Matteo Surely when the work is done during your sleep 😂

    posted in Pythonista read more
  • cvp

    @Matteo The script of omz did open a folder, your script runs a script, that makes the magic difference.

    Put a little sleep after webbrowser.open to let it time to perform its action before the remove

    import time
    time.sleep(0.2)
    

    posted in Pythonista read more
  • cvp

    @Matteo I think that it is not "magically". When you run a script, Pythonista opens its folder, thus...

    posted in Pythonista read more
  • cvp

    @Matteo to delete the file at end of your script

    Import os
    os.remove(folder_path+'.folder.py')
    

    posted in Pythonista read more
  • cvp

    @Matteo Every directory contains a . and a .. entry. (in Unix, Windows, etc...)

    . means the directory itself. It is called the current directory.

    .. means the directory's parent directory, that is, the directory that contains it.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!