コード例 #1
0
def main():
    global app
    datetime_from, datetime_end, task_type = parse_args()
    task_config = config.mopub_task_list[task_type]
    detail_log_file = task_config["detail_log_file"]
    clean_sql_file = task_config["clean_sql_file"]
    app["statics_log_file"] = task_config["statics_log_file"]

    init_logging(detail_log_file)

    sql_file_name = gen_sql_file_name()
    logging.info("main.sql_file_name.%s" % sql_file_name)

    p = toolkit.datetime_to_timestamp(datetime_from)
    g_stop_time = toolkit.datetime_to_timestamp(datetime_end)
    while p <= g_stop_time:
        main_loop(task_type, sql_file_name, p)
        p += 1 * 24 * 3600

    # 执行 SQL
    mysql_config = config.mysql_config
    toolkit.execute_mysql_sql(
        mysql_config['host'],
        mysql_config['port'],
        mysql_config["user"],
        mysql_config["passwd"],
        mysql_config["dbname"],
        sql_file_name)
    # END
    if clean_sql_file:
        os.remove(sql_file_name)
    else:
        logging.info("keep the tmp sql file @ %s" % sql_file_name)
    return
コード例 #2
0
def main():
    # datetime
    start_day, stop_day = toolkit.parse_args()
    start_timestamp = toolkit.datetime_to_timestamp(start_day)
    stop_timestamp = toolkit.datetime_to_timestamp(stop_day)
    # 每次最小时间跨度,单位:秒
    min_duration = 7 * 24 * 3600  # 7day
    times = int(stop_timestamp - start_timestamp) / int(min_duration)
    for i in xrange(times):
        start = start_timestamp + min_duration * i
        stop = start + min_duration
        main_loop((start, stop))
    start = start_timestamp + min_duration * times
    stop = stop_timestamp
    main_loop((start, stop))
コード例 #3
0
def main():
    global app
    datetime_from, datetime_end, task_type = parse_args()
    task_config = config.facebook_task_list[task_type]
    split_task = task_config["split_task"]
    size_per_split = task_config["size_per_split"]
    detail_log_file = task_config["detail_log_file"]
    clean_sql_file = task_config["clean_sql_file"]
    app["statics_log_file"] = task_config["statics_log_file"]

    init_logging(detail_log_file)

    sql_file_name = gen_sql_file_name()
    logging.info("main.sql_file_name.%s" % sql_file_name)

    if split_task:
        start_time = toolkit.datetime_to_timestamp(datetime_from)
        g_stop_time = toolkit.datetime_to_timestamp(datetime_end)
        while start_time < g_stop_time:
            stop_time = start_time + size_per_split * 24 * 3600
            if stop_time > g_stop_time:
                stop_time = g_stop_time
            main_loop(task_type, sql_file_name, start_time, stop_time)
            start_time += size_per_split * 24 * 3600
    else:
        start_time = toolkit.datetime_to_timestamp(datetime_from)
        stop_time = toolkit.datetime_to_timestamp(datetime_end)
        main_loop(task_type, sql_file_name, start_time, stop_time)

    # 执行 SQL
    mysql_config = config.mysql_config
    toolkit.execute_mysql_sql(mysql_config['host'], mysql_config['port'],
                              mysql_config["user"], mysql_config["passwd"],
                              mysql_config["dbname"], sql_file_name)

    # END
    if clean_sql_file:
        os.remove(sql_file_name)
    else:
        logging.info("keep the tmp sql file @ %s" % sql_file_name)
    return