<reponame>TheSampaio/DesktopVirtualAssistant
from os import truncate
from Includes import os, shutil, sleep
from AssistantConfig import voice, USERPATH

TIME = 10

def extension_type(event): # Get file's extension
    if event.src_path[event.src_path.rindex('.') + 1:] != 'tmp' or 'crdownload':
        return event.src_path[event.src_path.rindex('.') + 1:]

# --- Create respective folders for the extensions ----- #
def isText(event):
    if extension_type(event) == 'txt':
        return True
    return False

def isPDF(event):
    if extension_type(event) == 'pdf':
        return True
    return False

def isMP3(event):
    if extension_type(event) in ('mp3', "wav", "m4a", "flac", "aiff", "ogg"):
        return True
    return False

def isImage(event):
    if extension_type(event) in ('png', 'jpg', 'jpeg', 'bmp', 'gif', 'raw', 'ico'):
        return True
    return False

def isVideo(event):
    if extension_type(event) in ('mov', 'mp4', 'avi', 'flv', 'ts'):
        return True
    return False

def isWord(event):
    if extension_type(event) in ('doc', 'docx', 'odf'):
        return True
    return False

def isSpreadsheet(event):
    if extension_type(event) in ('xls', 'xlsx'):
        return True
    return False

def isPresentation(event):
    if extension_type(event) in ('ppt', 'pptx'):
        return True
    return False

def isCompacted(event):
    if extension_type(event) in ('rar', 'zip', '7z', 'iso'):
        return True
    return False

def isCode(event):
    if extension_type(event) in ('py', "jl", 'cs', 'js', 'php', 'html', 'sql', 'css', 'c', 'h', 'cpp', 'java', 'asp', 'aspx', 'axd', 'asx', 'asmx', 'ashx', 'cfm', 'yaws', 'swf', 'htm', 'xhtml', 'jhtml', "jsp", "jspx", "wss", "do", "cmd", "action", "pl", "phtml", "php3", "php4", "rb", "rhtml", "shtml", "rss", "svg", ):
        return True
    return False

def isExecutable(event):
    if extension_type(event) in ('exe', 'msi', 'run', 'deb'):
        return True
    return False

def isInvoice(event):
    if extension_type(event) in ('xml'):
        return True
    return False

def isTorrent(event):
    if extension_type(event) in ('torrent'):
        return True
    return False

def isPackage(event):
    if extension_type(event) in ('package'):
        return True
    return False
# ------------------------------------------------------ #

def makeFolder(event, foldername): # Create folders
    os.chdir('{}\\Downloads'.format(USERPATH))

    if extension_type(event) not in ('tmp', 'crdownload'):
        voice('Novo arquivo detectado')

        if os.path.exists(foldername):
            # voice('A pasta destino já existe')
            # voice('Pulando criação')
            return os.getcwd() + os.sep + str(foldername)

        else:
            os.mkdir(str(foldername))
            return os.getcwd() + os.sep + str(foldername)

def moveToFolder(event, path_to_new_folder): # Move files to inside folders
    if extension_type(event) not in ('tmp', 'crdownload'):
        try:
            voice('Movendo arquivo em {} segundos...'.format(TIME))
            sleep(TIME)

            shutil.move(event.src_path, path_to_new_folder)

            if event.src_path:
                voice('Arquivo movido com sucesso')

            else:
                pass

        except:
            voice('O arquivo já existe na pasta destino')

            fileName = event.src_path
            file = fileName.replace('{}\\Downloads\\'.format(USERPATH), '')

            try:
                os.remove(file) # Delete duplicated files
                voice('Deletei o arquivo para evitar duplicidades')

            except:
                pass

            pass

from os import truncate
from Includes import os, shutil, sleep
from AssistantConfig import voice, USERPATH

TIME = 10

def extension_type(event): # Get file's extension
    if event.src_path[event.src_path.rindex('.') + 1:] != 'tmp' or 'crdownload':
        return event.src_path[event.src_path.rindex('.') + 1:]

# --- Create respective folders for the extensions ----- #
def isText(event):
    if extension_type(event) == 'txt':
        return True
    return False

def isPDF(event):
    if extension_type(event) == 'pdf':
        return True
    return False

def isMP3(event):
    if extension_type(event) in ('mp3', "wav", "m4a", "flac", "aiff", "ogg"):
        return True
    return False

def isImage(event):
    if extension_type(event) in ('png', 'jpg', 'jpeg', 'bmp', 'gif', 'raw', 'ico'):
        return True
    return False

def isVideo(event):
    if extension_type(event) in ('mov', 'mp4', 'avi', 'flv', 'ts'):
        return True
    return False

def isWord(event):
    if extension_type(event) in ('doc', 'docx', 'odf'):
        return True
    return False

def isSpreadsheet(event):
    if extension_type(event) in ('xls', 'xlsx'):
        return True
    return False

def isPresentation(event):
    if extension_type(event) in ('ppt', 'pptx'):
        return True
    return False

def isCompacted(event):
    if extension_type(event) in ('rar', 'zip', '7z', 'iso'):
        return True
    return False

def isCode(event):
    if extension_type(event) in ('py', "jl", 'cs', 'js', 'php', 'html', 'sql', 'css', 'c', 'h', 'cpp', 'java', 'asp', 'aspx', 'axd', 'asx', 'asmx', 'ashx', 'cfm', 'yaws', 'swf', 'htm', 'xhtml', 'jhtml', "jsp", "jspx", "wss", "do", "cmd", "action", "pl", "phtml", "php3", "php4", "rb", "rhtml", "shtml", "rss", "svg", ):
        return True
    return False

def isExecutable(event):
    if extension_type(event) in ('exe', 'msi', 'run', 'deb'):
        return True
    return False

def isInvoice(event):
    if extension_type(event) in ('xml'):
        return True
    return False

def isTorrent(event):
    if extension_type(event) in ('torrent'):
        return True
    return False

def isPackage(event):
    if extension_type(event) in ('package'):
        return True
    return False
# ------------------------------------------------------ #

def makeFolder(event, foldername): # Create folders
    os.chdir('{}\\Downloads'.format(USERPATH))

    if extension_type(event) not in ('tmp', 'crdownload'):
        voice('Novo arquivo detectado')

        if os.path.exists(foldername):
            # voice('A pasta destino já existe')
            # voice('Pulando criação')
            return os.getcwd() + os.sep + str(foldername)

        else:
            os.mkdir(str(foldername))
            return os.getcwd() + os.sep + str(foldername)

def moveToFolder(event, path_to_new_folder): # Move files to inside folders
    if extension_type(event) not in ('tmp', 'crdownload'):
        try:
            voice('Movendo arquivo em {} segundos...'.format(TIME))
            sleep(TIME)

            shutil.move(event.src_path, path_to_new_folder)

            if event.src_path:
                voice('Arquivo movido com sucesso')

            else:
                pass

        except:
            voice('O arquivo já existe na pasta destino')

            fileName = event.src_path
            file = fileName.replace('{}\\Downloads\\'.format(USERPATH), '')

            try:
                os.remove(file) # Delete duplicated files
                voice('Deletei o arquivo para evitar duplicidades')

            except:
                pass

            pass
# Get file's extension # --- Create respective folders for the extensions ----- # # ------------------------------------------------------ # # Create folders # voice('A pasta destino já existe') # voice('Pulando criação') # Move files to inside folders # Delete duplicated files