Exemplo n.º 1
0
def save_to_db(conn, date, platform, revenue):
    logging.info("=" * 40)
    logging.info([date, platform, revenue])

    now_string = toolkit.mysql_now()

    update_sql = "  UPDATE revenue SET \t"
    update_sql += " `revenue` = '%s' ,\t" % revenue
    update_sql += " `updated_at` = '%s'\t" % now_string
    update_sql += ' WHERE\t'
    update_sql += " `platform` = '%s' AND\t" % platform
    update_sql += " `date` = '%s' ;" % date

    stat = toolkit.mysql_execute(conn, update_sql)
    if stat > 0:
        logging.info("saveToDb:SUCCESS:UPDATE_SQL:[%s][%s]" %
                     (update_sql, stat))
        return True
    else:
        insert_sql = "INSERT INTO revenue (`date`, `platform`, `revenue`)" \
                     " VALUES('%s','%s','%s');" \
                     % (date, platform, revenue)
        stat = toolkit.mysql_execute(conn, insert_sql)
        if stat > 0:
            logging.info("saveToDb:SUCCESS:INSERT_SQL:[%s][%s]" %
                         (insert_sql, stat))
            return True
        else:
            logging.error("saveToDb:FAIL:INSERT_SQL:[%s][%s]" %
                          (insert_sql, stat))
            return False
def save_to_db(conn, date, appname, country, placement, field_name, value):
    logging.info("=" * 40)
    logging.info((date, appname, country, placement, field_name, value))

    now_string = toolkit.mysql_now()

    UPDATE_SQL = "UPDATE ad_summary SET %s = %s ,updated_at = '%s' " \
                 "WHERE date = '%s' AND platform = '%s' AND app = '%s'" \
                 " AND country = '%s' ;" % \
                 (field_name, value, now_string, date, 'facebook', appname, country)
    # logging.info("saveToDb:INFO:UPDATE_SQL:[%s]" % (UPDATE_SQL))
    stat = toolkit.mysql_execute(conn, UPDATE_SQL)
    if stat > 0:
        logging.info("saveToDb:SUCCESS:UPDATE_SQL:[%s][%s]" %
                     (UPDATE_SQL, stat))
        return True
    elif field_name == 'revenue':
        INSERT_SQL = "INSERT INTO ad_summary (date,app,platform,country,%s)" \
                     " VALUES('%s','%s','facebook','%s',%s);" \
                     % (field_name, date, appname, country, value)
        stat = toolkit.mysql_execute(conn, INSERT_SQL)
        if stat > 0:
            logging.info("saveToDb:SUCCESS:INSERT_SQL:[%s][%s]" %
                         (INSERT_SQL, stat))
            return True
        else:
            logging.error("saveToDb:FAIL:INSERT_SQL:[%s][%s]" %
                          (INSERT_SQL, stat))
            return False
    else:
        logging.info("saveToDb:FAIL:UPDATE_SQL:[%s][%s]" % (UPDATE_SQL, stat))
        return False
def save_to_db(conn, mydata):
    logging.info("=" * 40)
    logging.info(mydata)

    now_string = toolkit.mysql_now()
    platform = 'googleplay'

    update_sql = "UPDATE ad_summary SET\t"
    update_sql += "`revenue` = '%s' ,\t" % mydata['revenue']
    update_sql += "`updated_at` = '%s' \t" % now_string
    update_sql += "WHERE\t"
    update_sql += "`date` = '%s' AND \t" % mydata['date']
    update_sql += "`app` = '%s' AND \t" % mydata['app']
    update_sql += "`country` = '%s' AND\t" % mydata['country']
    update_sql += "`platform` = '%s' ;" % platform

    stat = toolkit.mysql_execute(conn, update_sql)
    if stat > 0:
        logging.info("saveToDb:SUCCESS:UPDATE_SQL:[%s][%s]" %
                     (update_sql, stat))
        return True
    else:
        logging.info("saveToDb:FAIL:UPDATE_SQL:[%s]" % update_sql)
        insert_sql = "INSERT INTO ad_summary (`platform`,`country`,`app`,`date`,`revenue`)" \
                     " VALUES('%s','%s','%s','%s','%s');" \
                     % (platform, mydata['country'], mydata['app'], mydata['date'], mydata['revenue'])
        stat = toolkit.mysql_execute(conn, insert_sql)
        if stat > 0:
            logging.info("saveToDb:SUCCESS:INSERT_SQL:[%s][%s]" %
                         (insert_sql, stat))
            return True
        else:
            logging.error("saveToDb:FAIL:INSERT_SQL:[%s][%s]" %
                          (insert_sql, stat))
            return False
def save_to_db_new(conn, model):
    table_name = config.googleplay_task["table_name"]
    field_list = ["date", "platform", "revenue"]
    unique_key = [
        "date",
        "platform",
    ]
    sql = toolkit.gen_save_sql(table_name, model, field_list, unique_key)

    status = False
    try:
        toolkit.mysql_execute(conn, sql)
        status = True
    except Exception as e:
        logging.error("save_to_db_new():FAIL:[%s][%s]" % (sql, e))
        status = False
    finally:
        return status
Exemplo n.º 5
0
def save_to_db(conn, date, request, filled, impression, click, filled_rate,
               ctr, ecpm, revenue):
    logging.info("=" * 40)
    logging.info([
        date, request, filled, impression, click, filled_rate, ctr, ecpm,
        revenue
    ])

    now_string = toolkit.mysql_now()
    UPDATE_SQL = "UPDATE ad_summary " \
                 "SET request = %s , " \
                 "filled = %s ," \
                 "impression = %s ," \
                 "click = %s ," \
                 "filled_rate = %s ," \
                 "ctr = %s ," \
                 "ecpm = %s ," \
                 "revenue = %s ," \
                 "updated_at = '%s' " \
                 "WHERE date = '%s' AND platform = '%s' AND app = '%s' AND country = '%s';" % (
                     request, filled, impression, click,
                     filled_rate, ctr, ecpm, revenue, now_string, date, 'baidu', '99', '99')
    stat = toolkit.mysql_execute(conn, UPDATE_SQL)
    if stat > 0:
        logging.info("saveToDb:SUCCESS:UPDATE_SQL:[%s][%s]" %
                     (UPDATE_SQL, stat))
        return True
    else:
        logging.info("saveToDb:error:UPDATE_SQL:[%s]" % (UPDATE_SQL))
        INSERT_SQL = "INSERT INTO ad_summary (platform,country,app,date," \
                     "request,filled,impression,click,filled_rate,ctr,ecpm,revenue,updated_at)" \
                     " VALUES('baidu','99','99','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" \
                     % (date, request, filled, impression, click, filled_rate, ctr, ecpm, revenue, now_string)
        stat = toolkit.mysql_execute(conn, INSERT_SQL)
        if stat > 0:
            logging.info("saveToDb:SUCCESS:INSERT_SQL:[%s][%s]" %
                         (INSERT_SQL, stat))
            return True
        else:
            logging.error("saveToDb:FAIL:INSERT_SQL:[%s][%s]" %
                          (INSERT_SQL, stat))
            return False
Exemplo n.º 6
0
def save_to_db(conn, data):
    logging.info("=" * 40)
    logging.info(data)

    my_data = repack_data(data)
    update_sql = get_update_sql(my_data)
    # logging.info("saveToDb:INFO:UPDATE_SQL:[%s]" % (update_sql))
    stat = toolkit.mysql_execute(conn, update_sql)
    if stat > 0:
        logging.info("saveToDb:SUCCESS:UPDATE_SQL:[%s][%s]" % (update_sql, stat))
        return True
    else:
        logging.error("saveToDb:FAIL:UPDATE_SQL:[%s][%s]" % (update_sql, stat))
        insert_sql = get_insert_sql(my_data)
        stat = toolkit.mysql_execute(conn, insert_sql)
        if stat > 0:
            logging.info("saveToDb:SUCCESS:INSERT_SQL:[%s][%s]" % (insert_sql, stat))
            return True
        else:
            logging.error("saveToDb:FAIL:INSERT_SQL:[%s][%s]" % (insert_sql, stat))
            return False