Пример #1
0
def make_ad_document(campaignId, adgroupId, conn):
    isAdgroupPresent = False
    try:
        document = AdDocument()
        rows = getInfoFromDB(adgroupId, sql_adgroup, conn)
        row = None
        if rows:
            row = rows[0]

        if row is not None:
            isAdgroupPresent = True
        if isAdgroupPresent:
            document.tenant_id = row["tenant_id"] if row["tenant_id"] else 0  #1
            document.campaign_id = long(
                campaignId) if campaignId != "0" else long(
                    row["campaignId"])  #2
            document.adgroup_id = long(
                adgroupId) if adgroupId != "0" else 0  #3
            document.adomain = "rti.com"  #4   ??
            # 5  6  TBD
            document.banner_size = row["banner_size"] if row[
                "banner_size"] else ""  #7
            document.creative_type = row["creative_type"] if row[
                "creative_type"] else ""  #8
            document.instl = bool(row["instl"]) if row["instl"] else False  #9
            document.proximity_mode = row["proximity_mode"] if row[
                "proximity_mode"] else ""  #10
            creatives = None  #11
            target_profiles = None  #12
            geo_targets = None  #13
            publishers = None  #14
            document.status = row["status_flag"] if row[
                "status_flag"] else 6  #15
            setattr(document, 'del', bool(row["del"]))  #16
            document.rti_mode = AdDocument.BATCH  #17
            document.adv_bid_rates = row["bid_rate"] if row[
                "bid_rate"] else 0.0  #18
            document.is_secure = bool(
                row["is_secure"]) if row["is_secure"] else False  #19
            document.session_id = randint(0, 1000000)  #20
            document.pub_bid_rates = 0.0  #21
            document.kpi_ctr = row["kpi_ctr"] if row["kpi_ctr"] else 0.0  #22
            document.kpi_sar = row["kpi_sar"] if row["kpi_sar"] else 0.0  #23
            #24  TBD

        if isAdgroupPresent:
            #get targetprofile info from db
            targetprofiles_rows = getInfoFromDB(adgroupId, sql_targetprofiles,
                                                conn)
            if targetprofiles_rows:
                target_profiles = make_target_profiles(targetprofiles_rows)

            if target_profiles:
                document.MergeFrom(target_profiles)

            #get geotarget info from db
            geotargets_rows = getInfoFromDB(adgroupId, sql_geotargets, conn)
            '''
            conn_marketplace = getConnectWithDB(dbconfig_marketplace, "marketplace_pool")
            if geotargets_rows:
                insert_rows = []
                for row in geotargets_rows:
                    if row["lat"] and row["lng"] and row["radius"]:
                        data = {
                                "id" : row["gtId"],
                                "tenant_id" : row["tenant_id"],
                                "study_id" : document.session_id,
                                "address1" :  row["address1"] ,
                                "address2":   row["address2"],
                                "city":      row["city"],
                                "state":      row["state"],
                                "country":     row["country"],
                                "zipcode":      row["zip"] ,
                                "latittude":      row["lat"],
                                "longitude":      row["lng"],
                                "type":      row["geoType"],
                                "adgroup":      row["adGroup_id"],
                                "dma_code":      row["dma"],
                                "radius":      row["radius"]
                                }
                        insert_rows.append((
                                      (row["gtId"]),
                                      (row["tenant_id"]),
                                      (document.session_id),
                                      (row["address1"]) ,
                                      (row["address2"]),
                                      (row["city"]),
                                      (row["state"]),
                                      (row["country"]),
                                      (row["zip"]) ,
                                      (row["lat"]),
                                      (row["lng"]),
                                      (row["geoType"]),
                                      (row["adGroup_id"]),
                                      (row["dma"]),
                                      (row["radius"])
                                    ))
                insertInfoToDB(insert_rows, conn_marketplace)
            '''
            print geotargets_rows
            if geotargets_rows:
                geo_targets = make_geo_targets(geotargets_rows)
            if geo_targets:
                document.MergeFrom(geo_targets)
            #closeDB(conn_marketplace)
            #get creative info from db
            creative_rows = getInfoFromDB(adgroupId, sql_creatives, conn)
            if creative_rows:
                creatives = make_creatives(creative_rows)
            if creatives:
                document.MergeFrom(creatives)
        print document  # for final test when sending
        return document
    except Exception as e:
        print e
        return None
Пример #2
0
def make_ad_document(campaignId, adgroupId, conn):
    isAdgroupPresent = False
    try:
        document = AdDocument()
        rows = getInfoFromDB(adgroupId, sql_adgroup, conn)
        row = None
        if rows:
            row = rows[0]

        if row is not None:
            isAdgroupPresent = True
        if isAdgroupPresent:
            document.tenant_id = row["tenant_id"] if row["tenant_id"] else 0  #1
            document.campaign_id = long(
                campaignId) if campaignId != "0" else long(
                    row["campaignId"])  #2
            document.adgroup_id = long(
                adgroupId) if adgroupId != "0" else 0  #3
            document.adomain = "rti.com"  #4   ??
            # 5  6  TBD
            document.banner_size = row["banner_size"] if row[
                "banner_size"] else ""  #7
            document.creative_type = row["creative_type"] if row[
                "creative_type"] else ""  #8
            document.instl = bool(row["instl"]) if row["instl"] else False  #9
            document.proximity_mode = row["proximity_mode"] if row[
                "proximity_mode"] else ""  #10
            creatives = None  #11
            target_profiles = None  #12
            geo_targets = None  #13
            publishers = None  #14
            document.status = row["status_flag"] if row[
                "status_flag"] else 6  #15
            setattr(document, 'del', bool(row["del"]))  #16
            print "setting rti_mode"
            document.rti_mode = AdDocument.BATCH  #17
            document.adv_bid_rates = row["bid_rate"] if row[
                "bid_rate"] else 0.0  #18
            document.is_secure = bool(
                row["is_secure"]) if row["is_secure"] else False  #19
            document.session_id = randint(0, 1000000)  #20
            document.pub_bid_rates = 0.0  #21
            document.kpi_ctr = row["kpi_ctr"] if row["kpi_ctr"] else 0.0  #22
            document.kpi_sar = row["kpi_sar"] if row["kpi_sar"] else 0.0  #23
            #24  TBD

        if isAdgroupPresent:
            #get targetprofile info from db
            print "get targetprofile info from db"
            targetprofiles_rows = getInfoFromDB(adgroupId, sql_targetprofiles,
                                                conn)
            if targetprofiles_rows:
                target_profiles = make_target_profiles(targetprofiles_rows)

            if target_profiles:
                document.MergeFrom(target_profiles)

            #get geotarget info from db
            print "get geotarget info from db"
            geotargets_rows = getInfoFromDB(adgroupId, sql_geotargets, conn)
            print "got geotarget info from db"

            print "connecting to marketplace db"
            conn_marketplace = getConnectWithDB(dbconfig_marketplace,
                                                "marketplace_pool")
            print "connected to marketplace db"
            if geotargets_rows:
                arrLen = len(geotargets_rows)
                i = 0
                data = str()
                for row in geotargets_rows:
                    print i, " vs ", arrLen
                    i += 1
                    #                    data += '(' + str(row["gtId"]) + ',' + str(row["tenant_id"]) +  ',' + str(document.session_id) + ',' + str(row["address1"]) + ',' + str(row["address2"]) + ',' + str(row["city"]) + ',' + str(row["state"]) + ',' + str(row["country"]) + ',' + str(row["zip"]) + ',' + str(row["lat"]) + ',' + str(row["lng"]) + ',' + str(row["geoType"]) + ',' + str(row["adGroup_id"]) + ',' + str(row["dma"]) + ',' + str(row["radius"]) + '),'
                    if row["lat"] and row["lng"] and row["radius"]:
                        insertInfoToDB(row, document.session_id,
                                       conn_marketplace)
                print data
                geo_targets = make_geo_targets(geotargets_rows)
                if geo_targets:
                    document.MergeFrom(geo_targets)
            closeDB(conn_marketplace)
            #get creative info from db
            print "get creative info from db"
            creative_rows = getInfoFromDB(adgroupId, sql_creatives, conn)
            if creative_rows:
                creatives = make_creatives(creative_rows)
            if creatives:
                document.MergeFrom(creatives)
        print document  # for test
        return document
    except Exception as e:
        print e
        return None