Exemple #1
0
def deleteGivenFileNames(listWithFileNames, pathWhereFileLocated):
    for mFile in listWithFileNames:
        tempFileName = ut.checkOSSystem(pathWhereFileLocated + "\\" + mFile)
        if os.path.exists(tempFileName):
            os.remove(tempFileName)
        else:
            print("Error: Something went wrong with file name or its path !")
Exemple #2
0
def main(pathForDB, filesLimitationPerDir=50):
    # Get the name of db to use it on next function
    dbName = extractNameFromPath(pathForDB)
    dbLocatedPath = extractNameFromPath(pathForDB, needWholePath=True)
    dbBackupPath = ut.checkOSSystem(dbLocatedPath + "\\" + backupDir)
    # If doesn't exist create the main folder where will save the back up files
    checkExistanceOrCreateDir(dbBackupPath)
    checkIfExceedBackupLimitation(dbBackupPath, filesLimitationPerDir, dbName)
    createBackUpFile(pathForDB, dbBackupPath)
    print("Backup for " + dbName + " finished")
Exemple #3
0
def createBackUpFile(pathForDB, pathForProjectBackUp):
    con = sqlite3.connect(pathForDB)
    # Get the name from path
    nameOfBackupFile = createFileName(extractNameFromPath(pathForDB, True))
    # Get the path for backups
    customPathForBackupFile = ut.checkOSSystem(pathForProjectBackUp + '/' +
                                               nameOfBackupFile)
    bck = sqlite3.connect(customPathForBackupFile)
    with bck:
        con.backup(bck, pages=1, progress=progress)
    bck.close()
    con.close()
Exemple #4
0
def extractNameFromPath(mPath, needExtension=False, needWholePath=False):
    # If it is Windows
    if os.name == "nt":
        tempStringList = mPath.split("\\")
    # If it is Unix
    else:
        tempStringList = mPath.split("/")

    if needWholePath:
        # To seperate the string we need to now the number of substrings
        sizeOfSubStrings = len(tempStringList)
        pathDBLocated = "\\".join(tempStringList[0:sizeOfSubStrings - 1])
        return ut.checkOSSystem(pathDBLocated)
    else:
        nameOfDB = tempStringList[-1]
        # Check if need to return name with extension or not
        if not needExtension:
            # Cut the extension
            nameOfDB = nameOfDB.split('.')[0]
        return nameOfDB
def createInfoMsgToSend(elementList):

    # Open connection with SQLite DB to interact with it
    dbConnection = sqlT.dbOpenConnection(ut.checkOSSystem(ut.findParentPath(dbFile)))

    # Loop that add data on message.txt
    for anElementListM in elementList:

        # A attribute that contains name of movie
        nameOfMovie = anElementListM.findAll("a", {"class": "headinglink"})[0]        
        nameOfMovieText = re.sub(r'(?<!\\)\'', "\'\'", nameOfMovie.text)
        
        # IMG attribute that contains image of movie
        imageOfMovie = anElementListM.findAll("img", {"class": "lozad"})[0].get('data-src')

        # DIV attribute that contains imdb grade (if doesn't show only subs4free grade)
        movieGradeAsHtml = str(anElementListM.findAll("div", {"class": "panel-heading-info"}))
        
        # To check if grade exist 
        locationOfGrade = movieGradeAsHtml.lower().find("imdb")        
        gradeOfMovie =  extractImdbGradeFromText(movieGradeAsHtml)
        
        # Search in base if movie alreay exist and return it
        mRes = sqlT.dbSELECT(dbConnection, 'MoviesTb', whereStatementText= "Title = '"+nameOfMovieText + "'")       
        
        if not mRes:
            # If entry doesn't exist insert new row
            sqlT.dbINSERT(dbConnection, "MoviesTb", ['Title', 'Grade', 'Notified', 'ImageUrl', 'EntryDate'], [nameOfMovieText, gradeOfMovie, 1, imageOfMovie, datetime.datetime.now().timestamp()])       
        elif len(mRes)==1:
            # If entry does exist update the row
            if locationOfGrade != -1 or gradeOfMovie != -1:
                sqlT.dbUPDATE(dbConnection, "MoviesTb", ['Grade', 'ImageUrl', 'ModifyDate'], [gradeOfMovie, imageOfMovie, datetime.datetime.now().timestamp()], "ID = " + str(mRes[0]['ID']))
            else:
                # If grade is not valid don't add it
                sqlT.dbUPDATE(dbConnection, "MoviesTb", ['ImageUrl', 'ModifyDate'], [imageOfMovie, datetime.datetime.now().timestamp()], "ID = " + str(mRes[0]['ID']))
        
    sqlT.dbCloseConnection(dbConnection)
Exemple #6
0
def createFileName(dbName):
    # current timestamp with milisec
    mTimeStamp = round(time.time() * 1000)
    return str(mTimeStamp) + "_" + dbName


# Start of the script that checks the given arguments
if __name__ == "__main__":
    # The number of arguments that user user
    numOfArg = len(sys.argv)
    # arg[1] = Path for DB
    if numOfArg == 2:
        # Call the main function wit
        # Checking if db exist (simultaneously)
        if ut.checkIfFileExists(ut.checkIfFileExists(sys.argv[1])):
            main(ut.checkOSSystem(sys.argv[1]))
        else:
            raise Exception("File of given db doesn't exist !")
    # arg[1] = Path for DB, arg[2] = Limit of files per directory
    elif numOfArg == 3:
        # Call the main function with checking if db exist (simultaneously)
        try:
            ut.checkIfFileExists(ut.checkOSSystem(sys.argv[1]))
            main(ut.checkOSSystem(sys.argv[1]),
                 filesLimitationPerDir=int(sys.argv[2]))
        except ValueError:
            raise Exception("The second argument is Invalid ! : %s" %
                            ValueError)
    else:
        raise Exception(
            "Script require argument(s) to start. Please visit ToolTutorial.txt to learn more about it."