コード例 #1
0
def main(options, logger=None):
    if logger == None:
        logger = Logger("download.log", "download.py", True, True)
    else:
        logger.context = "download.py"
    try:
        query = utils.getQuery()
        logger.context = "download.py"
        if __name__ == "__main__":
            utils.log_header(logger, DESCRIPTION,
                             options.get("verbose", False))

        logger.debug("Options:", options.get("verbose", False))
        for i in options:
            logger.debug(i + ": " + str(options[i]),
                         options.get("verbose", False))
        download_query(query, options, logger)

        # move all downloaded videos in videos directory
        repoDir = utils.repoPath()
        fs = os.listdir(repoDir)
        for f in fs:
            if utils.is_video(f):
                os.rename(f, "videos/" + f)
        logger.success("All files downloaded.",
                       not options.get("silent", False))
    except Exception as e:
        logger.handle_exception(e)
        raise e
コード例 #2
0
ファイル: base.py プロジェクト: mithem/Stater
def exec_sql(sql_command="SELECT * FROM tasks", verbose=True, logger: Logger = None):
    """Execute sql_command on database and return None or whatever is returned from the database. If sql_command is not specified, all tasks will get returned"""
    result = None
    if logger != None and type(logger) == Logger:
        logger.set_context("exec_sql")
    elif verbose == True:
        logger = Logger("exec_sql.log", "exec_sql", True, True)
    try:
        connection = pymysql.connect(host='localhost',
                                     user='******',
                                     password='******',
                                     db='stater',
                                     charset='utf8mb4',
                                     cursorclass=pymysql.cursors.DictCursor)
    except OperationalError as e:
        logger.handle_exception(e)
        raise AuthenticationError("Access denied to database")
    if verbose and logger != None:
        logger.success("connected to database", False)
    if verbose and logger != None:
        logger.debug("executing SQL-Command: " + sql_command)
    with connection.cursor() as cursor:
        cursor.execute(sql_command)
        if "SELECT" in sql_command:
            result = cursor.fetchall()
        else:
            connection.commit()
    if verbose and logger != None:
        logger.debug("SQL query returned: " + str(result))
    try:
        connection.close()
        if verbose and logger != None:
            logger.success("Shut down connection to database", False)
    except Exception as e:
        if logger != None and type(logger) == Logger:
            logger.handle_exception(e)
        else:
            print(e)
    finally:
        return result