Пример #1
0
def insert_photos_MD5(db_name, table_name, **kw):
    print("Starting")
    db = pymysql.connect("192.168.1.100", "root", "root", db_name)
    # 使用cursor()方法获取操作游标
    cursor = db.cursor()
    if kw.get('data_list'):
        data_list = kw.get('data_list')
    else:
        data_list = []
    if kw.get('city'):
        city = kw.get('city')
    else:
        city = "未传城市参数city"
    data_need_update_list = data_list  # 需要更新的数组

    logger.info("[%s] city: %s, db: %s, table: %s, total update MD5 files: %s", common.format_ymdhms_time_now(), city,
                db_name, table_name, str(len(data_need_update_list)))

    step = 10000  # 每次更新step个
    step_num = math.ceil(len(data_need_update_list) / step)

    try:
        for i in range(step_num):
            head = i * step
            if i == (step_num - 1):
                tail = len(data_need_update_list)
            else:
                tail = (i + 1) * step
            insert_sql = ""
            insert_sql_head = " INSERT INTO `{table_name}`(`city`, `file_name`, `iden_id`, `MD5`) "
            insert_sql_head = insert_sql_head.format(table_name=table_name)
            insert_sql_body = " (\"{city}\", \"{file_name}\", \"{iden_id}\", \"{MD5}\") "
            temp_index = 0
            for city, file_name, iden_id, MD5 in data_need_update_list[head:tail]:
                if temp_index == 0:
                    insert_sql += insert_sql_head
                    insert_sql += " VALUES "
                else:
                    insert_sql += ", "
                insert_sql += insert_sql_body.format(city=city, file_name=file_name, iden_id=iden_id, MD5=MD5)
                temp_index += 1

            # logger.info("[%s] city: %s, db: %s, table: %s, sql: %s", common.format_ymdhms_time_now(), city,
            #             db_name, table_name, insert_sql)

            cursor.execute(insert_sql)

    except:
        print("更新到数据库失败")
        return False

    db.commit()
    db.close()
    return True
Пример #2
0
def logger_setup():
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    formatter = logging.Formatter("%(levelname)7s: %(name)30s: %(message)s")

    handler = logging.FileHandler(filename=log_path)
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    consoleHandler = logging.StreamHandler()
    consoleHandler.setLevel(logging.DEBUG)
    consoleHandler.setFormatter(formatter)
    logger.addHandler(consoleHandler)

    _logger.info("Logger", "Logger saving at", str(log_path))
Пример #3
0
def insert_city(**kw):
    if kw.get("city"):
        city = kw.get("city")
    else:
        return False, [], {}
    if kw.get("city_name_chinese"):
        city_name_chinese = kw.get("city_name_chinese")
    else:
        return False, [], {}
    city_name_list = []
    city_name_map = {}

    table_name = city+"_dp"
    history_table_name = city+"_dp_history"

    db = db_connect("ws_doorplate")
    # 使用cursor()方法获取操作游标
    cursor = db.cursor()
    create_sql = " CREATE  TABLE IF NOT EXISTS {table_name} (LIKE dp_template) ".format(table_name=table_name)
    logger.info(create_sql)
    try:
        cursor.execute(create_sql)
        db.commit()
    except:
        logger.info("创建城市数据表失败")
    create_history_sql = " CREATE  TABLE IF NOT EXISTS {history_table_name} (LIKE dp_history_template) ".format(history_table_name=history_table_name)
    logger.info(create_history_sql)
    try:
        cursor.execute(create_history_sql)
        db.commit()
    except:
        logger.info("创建城市历史表失败")
    insert_sql = "INSERT INTO `ws_doorplate`.`cities`(`city`, `city_name_chinese`, `city_db`, `city_table`) VALUES ('{city}', '{city_name_chinese}', 'ws_doorplate', '{table_name}');"
    insert_sql = insert_sql.format(city=city, city_name_chinese=city_name_chinese, table_name=table_name)
    logger.info(insert_sql)
    try:
        cursor.execute(insert_sql)
        db.commit()
    except:
        logger.info("插入城市名称失败")
    city_name_list, city_name_map, city_name_db_map, city_name_table_map = get_city_name()
    db.close()
    return True, city_name_list, city_name_map
from App import logger_setup, logger, name, version, author

if __name__ == "__main__":
    logger_setup()
    logger.info("Setup", "Logger has been setup")

    import OpenGL
    import OpenGL.GL
    import OpenGL.GLUT
    import OpenGL.GLU

    logger.info("Setup", "OpenGL has been setup")
    logger.empty()
    logger.info(" ", "---", name, "---")
    logger.info(" ", "Version", version)
    logger.info(" ", "By", author)
    logger.info(" ", "----" + str().join(["-" for _ in name]) + "----")
    logger.empty()
    logger.info(name, "Starting!")