예제 #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
예제 #3
0
파일: workflow.py 프로젝트: mithem/ytHelper
arguments = parser.parse_args()
args = vars(arguments)
VERBOSE = args.get("verbose", False)

log = Logger("workflow.log", "workflow.py", True, True)
utils.log_header(log, DESCRIPTION, VERBOSE)

try:
    log.debug("Debug mode activated.", VERBOSE)
    log.debug("Args: ", VERBOSE)
    for i in args:
        log.debug(i + ": " + str(args[i]), VERBOSE)
    if not args.get("test", False):
        download.main(args, logger=log)
    if args.get("facerec", None) != None and not args.get("test", False):
        if "all" in args.get("facerec", []):
            # pass all videos from utils.getVideos() to facerec
            facerec.main({"files": utils.getVideos()})
        else:
            # pass all videos from args to facerec
            facerec.main({"files": args.get("facerec", [])})
    if not args.get("test", False):
        convert.main(args, log)
    if not args.get("test", False):
        transfer.main(args, log)
    log.success("Workflow routine finished!", not args.get("silent", False))
except KeyboardInterrupt:
    log.context = "workflow.py"
    log.warning("exiting...", True)
    exit(0)