예제 #1
0
    def post(self):
        err = JsOb()
        if not self.json._ids:
            err.apply = u'offer can\'t be Null!'

        if not err:
            offers = []
            for offer_id in self.json._ids:
                affiliate_id = self.current_user_id
                off_aff = OfferAffiliate.find_one(
                    dict(offer_id=int(offer_id),
                         affiliate_id=int(affiliate_id),
                         deleted=False))
                offer = Offers.find_one(dict(_id=int(offer_id)))
                status = '1' if offer.access_status == '1' else '2'
                if not off_aff:
                    off_aff = OfferAffiliate._save(
                        **dict(offer_id=int(offer_id),
                               affiliate_id=int(affiliate_id),
                               status=status,
                               payout=offer.payment))
                else:
                    off_aff.payout = offer.payment
                    off_aff.status = status
                    off_aff.save()
                offers.append(offer)
            self.finish(dict(offers=offers, err=False))
        else:
            self.render(err)
예제 #2
0
    def send_email(self, pause_date, offer_id):
        offer = Offers.find_one(dict(_id=int(offer_id)))
        offer_affiliate = OAffiliate.find(
            dict(offer_id=int(offer_id), status='1'), dict(affiliate_id=1))
        affiliate_uses = User.find(
            dict(_id={
                "$in":
                [int(off_aff.affiliate_id) for off_aff in offer_affiliate]
            }), dict(email=1))

        emails = map(lambda user: user.email, affiliate_uses)
        if not emails:
            return False
        recivers = reduce(lambda email_1, email_2: email_1.extend(email_2),
                          emails, [])
        content = dict(
            user_id=self.current_user_id,
            model_id=0,
            receiver=recivers,
            message=u'The offer named {offer} will be paused on {pause_date}'.
            format(offer=offer.title, pause_date=pause_date),
            subject=u'Leadhug offer paused notification',
            sender=self.current_user.account)
        EMail._create(**content)
        return True
예제 #3
0
    def post(self):
        err = JsOb()
        pause_date = self.json.pause_date
        if not pause_date:
            err.pause_date = u'pause_date cat\'t be empty!'
        elif Tool.str_datetime(pause_date,
                               '%Y-%m-%d %H:%M:%S') <= datetime.datetime.now():
            err.pause_date = u'The pause time can\'t less than Now!'

        if not err:
            self.offer_id = self.json.offer_id
            job_type = 'date'
            store_executor_alias = 'offer'
            process_count = 5
            max_instances = 100
            scheduler = ScheInterface(job_type, store_executor_alias,
                                      process_count)
            res = scheduler.add_date_job(pause, [self.offer_id], pause_date,
                                         max_instances, self.job_listener)
            if res:
                scheduler.sche.start()
                self.send_email(pause_date, self.offer_id)
                offer = Offers.find_one(dict(_id=int(self.offer_id)))
                offer.pause_job_set = True
                offer.last_update = DateTime().current_time
                offer.save()
            else:
                err.pause_date = 'Add pause job failure!'

        self.render(err)
예제 #4
0
    def get(self):
        status = {'0': 'Paused', '1': 'Active', '2': 'Pending'}
        offer_id = self.get_argument('offer_id')
        offer = Offers.find_one(dict(_id=int(offer_id)))
        if not offer:
            self.write(u'The offer is not exist!')
            return
        offer.status = status.get(offer.status)
        if offer.advertiser_id:
            ad = User._get(offer.advertiser_id)
            offer['advertiser'] = ad.account if ad else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        if offer.access_status == '1':
            offer.access_status = 'Public'
        elif offer.access_status == '2':
            offer.access_status = 'Need Approve'
        else:
            offer.access_status = 'Private'

        if offer.platform == '1':
            offer.platform = 'IOS'
        elif offer.platform == '2':
            offer.platform = 'ANDROID'
        elif offer.platform == '0':
            offer.platform = 'All'

        offer_affiliates = OAffiliate._query(offer_ids=[offer_id])
        for off_aff in offer_affiliates:
            affiliate = User.find_one(dict(_id=int(off_aff.affiliate_id)))
            affiliate_extend = Affiliate.find_one(
                dict(user_id=int(off_aff.affiliate_id)))
            if not affiliate_extend or not affiliate_extend.account_manager:
                off_aff['am_name'] = ''
            elif off_aff.status == '1':
                am = User.find_one(
                    dict(_id=int(affiliate_extend.account_manager)))
                off_aff['am_name'] = am.account
            off_aff['affiliate_name'] = affiliate.account if affiliate else ''
            if off_aff.status == '1':
                off_aff['application_status'] = 'Approved'
            elif off_aff.status == '2':
                off_aff['application_status'] = 'Pending'
            else:
                off_aff['application_status'] = 'Rejected'

        self.render(offer=offer, offer_affiliates=offer_affiliates)
예제 #5
0
 def get(self, offer_id):
     advertiser_extends = Advertisers.find(dict(status={"$ne": '0'}))
     ads = User.find(
         dict(_id={'$in': [int(ad.user_id) for ad in advertiser_extends]},
              deleted=False))
     cat = Category._query()
     offer = Offers.find_one(dict(_id=int(offer_id)))
     self.render(cat=cat,
                 ads=ads,
                 offer_id=offer_id,
                 offer=offer,
                 countries=c().countries)
예제 #6
0
 def get(self, offer_id):
     err = JsOb()
     offer = Offers.find_one(dict(_id=int(offer_id)))
     if not offer:
         err.ad_info = "not found!"
     if err:
         self.render(err)
     else:
         offer.deleted = True
         offer._id = int(offer._id)
         offer.save()
     self.redirect("/offers/manage")
예제 #7
0
    def get_sum(cls, data):
        data_dict = {}
        for doc in data:
            offer_id = doc.offer_id
            offer = Offers.find_one(dict(_id=int(offer_id)))
            # offer = Offers.find_one(dict(_id=int(offer_id)))
            data_dict.setdefault(offer_id, defaultdict(lambda: 0))
            data_dict[offer_id]['offer_id'] = offer_id
            data_dict[offer_id]['offer_name'] = offer.title
            data_dict[offer_id]['payout'] += doc.payout
            data_dict[offer_id]['actions'] += doc.actions
            data_dict[offer_id]['amount'] += doc.amount

        return data_dict
예제 #8
0
    def get(self):
        offer_id = self.get_argument('offer_id', None, strip=True)
        offer = Offers.find_one(dict(_id=int(offer_id)))
        off_aff = OfferAffiliate.find_one(
            dict(offer_id=int(offer._id),
                 affiliate_id=int(self.current_user_id),
                 deleted=False))

        if offer.platform == '1':
            offer.platform = 'IOS'
        elif offer.platform == '2':
            offer.platform = 'ANDROID'
        elif offer.platform == '0':
            offer.platform = 'All'

        if off_aff:
            if off_aff.payout:
                offer.payment = off_aff.payout
            if off_aff.day_cap:
                offer.day_cap = off_aff.day_cap
            if off_aff.month_cap:
                offer.month_cap = off_aff.month_cap
            if off_aff.total_cap:
                offer.total_cap = off_aff.total_cap

            if offer.access_status == '1':
                offer['application_status'] = '1'
            if offer.access_status == '2':
                if off_aff.status == '1':
                    offer['application_status'] = '1'
                else:
                    offer['application_status'] = off_aff.status
        else:
            offer['application_status'] = '3'
        if offer.category_id:
            category = Category.find_one(dict(_id=int(offer.category_id)))
            if category:
                offer['category'] = category.name
        self.render(
            aff_id=self.current_user_id,
            offer=offer,
        )
예제 #9
0
    def post(self):
        err = JsOb()
        content = loads(self.request.body)
        if content.get('affiliate_ids'):
            affiliate_ids = [int(_id) for _id in content.get('affiliate_ids')]
            affiliates = User.find(dict(_id={'$in': affiliate_ids}))
            for aff in affiliates:
                content['affiliate_id'] = aff._id
                if not content.get('payout'):
                    offer = Offers.find_one(
                        dict(_id=int(content.get('offer_id'))))
                    content['payout'] = offer.payment
                OAffiliates._save(**content)

        elif content.get('offer_ids'):
            offer_ids = [int(_id) for _id in content.get('offer_ids')]
            offers = Offers.find(dict(_id={'$in': offer_ids}))
            for offer in offers:
                content['offer_id'] = offer._id
                OAffiliates._save(**content)

        off_affs = OAffiliates.find(dict(status={'$ne': '0'}))
        self.finish(dict(off_affs=off_affs))
예제 #10
0
    def get(self):
        affiliate_user_id = self.get_argument('affiliate_id')
        affiliate = Affiliate.find_one(dict(user_id=int(affiliate_user_id)))
        affiliate_user = User.find_one(dict(_id=int(affiliate_user_id)))
        if not affiliate or not affiliate_user:
            self.write(u'The affiliate is not exist!')
            return
        affiliate._id = affiliate.user_id
        affiliate['name'] = affiliate_user.account
        affiliate['email'] = affiliate_user.email
        affiliate['skype_id'] = affiliate_user.skype_id

        offer_affiliates = OAffiliate._query(affiliate_id=affiliate._id)
        for off_aff in offer_affiliates:
            offer = Offers.find_one(dict(_id=int(off_aff.offer_id)))
            off_aff['offer_title'] = offer.title if offer else ''
            if off_aff.status == '1':
                off_aff['application_status'] = 'Approved'
            elif off_aff.status == '2':
                off_aff['application_status'] = 'Pending'
            else:
                off_aff['application_status'] = 'Rejected'
        self.render(affiliate=affiliate, offer_affiliates=offer_affiliates)
예제 #11
0
def get_report():
    """
    """
    http = httplib2.Http()
    url_ios = "https://api.taptica.com/v2/bulk?token=O%2fhjVq4UFGiM6fiHJBo2sw%3d%3d&platforms=iPhone"
    url_android = "https://api.taptica.com/v2/bulk?token=O%2fhjVq4UFGiM6fiHJBo2sw%3d%3d&platforms=android"
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    response_ios, content_ios = http.request(url_ios, 'GET', headers=headers)
    response_android, content_android = http.request(url_android,
                                                     'GET',
                                                     headers=headers)
    offers_ios = yajl.loads(content_ios)['Data']
    offers_android = yajl.loads(content_android)['Data']
    offers = offers_ios + offers_android
    offers_list_new = []  ##
    offers_list_old = OfferList.find_one(dict(
        _id=96)).offer_list if OfferList.find_one(dict(_id=96)) else []  ##
    for offer in offers:
        o = Offers(parse_offer(offer))
        re = Offers.find_one(
            dict(title=o.title,
                 geo_targeting=o.geo_targeting,
                 click_url=o.click_url))
        if re:
            offers_list_new.append(re._id)  ##
            re.is_expired = False  ##
            re.advertiser_id = o.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.package_name = o.package_name
            re.title = o.title
            re.preview_url = o.preview_url
            re.desciption = o.desciption
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.total_cap = o.total_cap
            re.cap = o.cap
            re.click_url = o.click_url
            re.icon_url = o.icon_url
            re.mini_version = o.mini_version
            re.payment = o.payment
            re.platform = o.platform
            re.geo_targeting = o.geo_targeting
            re.banner_url = o.banner_url
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False  ##
            offers_list_new.append(o._id)  ##
            o.save()
    offers_list = OfferList.find_one(dict(_id=96))  ##
    if offers_list:  ##
        offers_list._id = 96  ##
        offers_list.offer_list = offers_list_new  ##
        offers_list.save()  ##
    else:  ##
        offers_list = OfferList(  ##
            dict(  ##
                _id=96,  ##
                offer_list=offers_list_new  ##
            )  ##
        )  ##
        offers_list.save()  ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new))  ##
    for offer_id in is_expired_offers:  ##
        offer = Offers.find_one(dict(_id=offer_id))  ##
        try:
            offer.is_expired = True  ##
            offer.save()
        except AttributeError:
            continue
예제 #12
0
def get_report():
    """
    """
    http = httplib2.Http()
    url_ios = "http://api.acekoala.com/api/offers?app_key=4603af3476d9b60bfc5d5cdaa577bdca&platform=Ios"
    url_android = "http://api.acekoala.com/api/offers?app_key=4603af3476d9b60bfc5d5cdaa577bdca&platform=Android"
    # url_ios = "http://api.acekoala.com/api/offers?app_key=8dedbea4d48580075b14cd083e5c5f8e&platform=Android"
    # url_android = "http://api.acekoala.com/api/offers?app_key=8dedbea4d48580075b14cd083e5c5f8e&platform=Android&country=us,ru"
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    response_ios, content_ios = http.request(url_ios, 'GET', headers=headers)
    response_android,content_android = http.request(url_android, 'GET', headers=headers)
    offers_ios = yajl.loads(content_ios)['data']
    offers_android = yajl.loads(content_android)['data']
    offers = offers_ios + offers_android
    offers_list_new = [] ##
    offers_list_old = OfferList.find_one(dict(_id=137)).offer_list if OfferList.find_one(dict(_id=137)) else [] ##
    for offer in offers:
        o = Offers(parse_offer(offer))
        re = Offers.find_one(dict(title=o.title, geo_targeting=o.geo_targeting, click_url=o.click_url))
        if re:
            offers_list_new.append(re._id) ##
            re.is_expired = False ##
            re.advertiser_id = o.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.package_name = o.package_name
            re.title = o.title
            re.preview_url = o.preview_url
            re.desciption = o.desciption
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.total_cap = o.total_cap
            re.cap = o.cap
            re.click_url = o.click_url
            re.icon_url = o.icon_url
            re.mini_version = o.mini_version
            re.payment = o.payment
            re.platform = o.platform
            re.geo_targeting = o.geo_targeting
            re.banner_url = o.banner_url
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False ##
            offers_list_new.append(o._id) ##
            o.save()
    offers_list = OfferList.find_one(dict(_id=137)) ##
    if offers_list: ##
        offers_list._id = 137 ##
        offers_list.offer_list = offers_list_new ##
        offers_list.save() ##
    else: ##
        offers_list = OfferList( ##
            dict( ##
                _id=137, ##
                offer_list=offers_list_new ##
            ) ##
        ) ##
        offers_list.save() ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new)) ##
    for offer_id in is_expired_offers: ##
        offer = Offers.find_one(dict(_id=offer_id)) ##
        try:
            offer.is_expired = True ##
            offer.save()
        except AttributeError:
            continue
예제 #13
0
def get_report():
    """
    """
    http = httplib2.Http()
    url = "http://api.c.avazunativeads.com/s2s?sourceid=21804&pagenum=10000&page=1"
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    response, content = http.request(url, 'GET', headers=headers)
    offers = yajl.loads(content)['ads']['ad']
    offers_list_new = [] ##
    offers_list_old = OfferList.find_one(dict(_id=153)).offer_list if OfferList.find_one(dict(_id=153)) else [] ##
    for offer in offers:
        o = Offers(parse_offer(offer))
        re = Offers.find_one(dict(title=o.title, geo_targeting=o.geo_targeting, click_url=o.click_url))
        if re:
            offers_list_new.append(re._id) ##
            re.is_expired = False ##
            re.advertiser_id = o.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.package_name = o.package_name
            re.title = o.title
            re.desciption = o.desciption
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.total_cap = o.total_cap
            re.cap = o.cap
            re.click_url = o.click_url
            re.icon_url = o.icon_url
            re.mini_version = o.mini_version
            re.payment = o.payment
            re.platform = o.platform
            re.geo_targeting = o.geo_targeting
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False ##
            offers_list_new.append(o._id) ##
            o.save()
    offers_list = OfferList.find_one(dict(_id=153)) ##
    if offers_list: ##
        offers_list._id = 153 ##
        offers_list.offer_list = offers_list_new ##
        offers_list.save() ##
    else: ##
        offers_list = OfferList( ##
            dict( ##
                _id=153, ##
                offer_list=offers_list_new ##
            ) ##
        ) ##
        offers_list.save() ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new)) ##
    for offer_id in is_expired_offers: ##
        offer = Offers.find_one(dict(_id=offer_id)) ##
        try:
            offer.is_expired = True ##
            offer.save()
        except AttributeError:
            continue
예제 #14
0
def get_report():
    """
    """
    http = httplib2.Http()
    url_ios = "https://admin.appnext.com/offerApi.aspx?id=dbc2d386-5f74-4817-a0a6-1b688877ea24"
    url_android = "https://admin.appnext.com/offerApi.aspx?id=cdd8008b-da30-42e3-be36-c64c6bf536ea"
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    response_ios, content_ios = http.request(url_ios, 'GET', headers=headers)
    response_android, content_android = http.request(url_android,
                                                     'GET',
                                                     headers=headers)
    offers_ios = yajl.loads(content_ios)['apps']
    offers_android = yajl.loads(content_android)['apps']
    offers_list_new = []  ##
    offers_list_old = OfferList.find_one(dict(
        _id=111)).offer_list if OfferList.find_one(dict(_id=111)) else []  ##
    for offer in offers_ios:
        o = Offers(parse_ios_offer(offer))
        re = Offers.find_one(
            dict(title=o.title,
                 geo_targeting=o.geo_targeting,
                 click_url=o.click_url))
        if re:
            offers_list_new.append(re._id)  ##
            re.is_expired = False  ##
            re.advertiser_id = o.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.package_name = o.package_name
            re.title = o.title
            # re.preview_url = o.preview_url
            re.desciption = o.desciption
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.total_cap = o.total_cap
            re.cap = o.cap
            re.click_url = o.click_url
            re.icon_url = o.icon_url
            re.mini_version = o.mini_version
            re.payment = o.payment
            re.platform = o.platform
            re.geo_targeting = o.geo_targeting
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False  ##
            offers_list_new.append(o._id)  ##
            o.save()

    for offer in offers_android:
        o = Offers(parse_android_offer(offer))
        re = Offers.find_one(
            dict(title=o.title,
                 geo_targeting=o.geo_targeting,
                 click_url=o.click_url))
        if re:
            offers_list_new.append(re._id)  ##
            re.is_expired = False  ##
            re.advertiser_id = o.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.package_name = o.package_name
            re.title = o.title
            re.preview_url = o.preview_url
            re.desciption = o.desciption
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.total_cap = o.total_cap
            re.cap = o.cap
            re.click_url = o.click_url
            re.icon_url = o.icon_url
            re.mini_version = o.mini_version
            re.payment = o.payment
            re.platform = o.platform
            re.geo_targeting = o.geo_targeting
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False  ##
            offers_list_new.append(o._id)  ##
            o.save()
    offers_list = OfferList.find_one(dict(_id=111))  ##
    if offers_list:  ##
        offers_list._id = 111  ##
        offers_list.offer_list = offers_list_new  ##
        offers_list.save()  ##
    else:  ##
        offers_list = OfferList(  ##
            dict(  ##
                _id=111,  ##
                offer_list=offers_list_new  ##
            )  ##
        )  ##
        offers_list.save()  ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new))  ##
    for offer_id in is_expired_offers:  ##
        offer = Offers.find_one(dict(_id=offer_id))  ##
        try:
            offer.is_expired = True  ##
            offer.save()
        except AttributeError:
            continue
예제 #15
0
def pause(offer_id):
    offer = Offers.find_one(dict(_id=int(offer_id)))
    if offer:
        offer.status = '0'
        offer.last_update = DateTime().current_time
        offer.save()
예제 #16
0
def get_report():
    """
    """
    http = httplib2.Http()
    url = "http://cpactions.com/api/v1.0/feed/public/offers?site_id=10459&hash=bfd486e491d72d38c533af53ee3c47b3097bafed&filters[avg_cr][gt]=0.01"
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    response, content = http.request(url, 'GET', headers=headers)
    offers = yajl.loads(content)['offers']
    offers_list_new = []  ##
    offers_list_old = OfferList.find_one(dict(
        _id=91)).offer_list if OfferList.find_one(dict(_id=91)) else []  ##
    for offer in offers:
        o = Offers(parse_offer(offer))
        re = Offers.find_one(
            dict(title=o.title,
                 geo_targeting=o.geo_targeting,
                 click_url=o.click_url))
        if re:
            offers_list_new.append(re._id)  ##
            re.is_expired = False  ##
            re.advertiser_id = o.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.package_name = o.package_name
            re.title = o.title
            re.preview_url = o.preview_url
            re.desciption = o.desciption
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.total_cap = o.total_cap
            re.cap = o.cap
            re.click_url = o.click_url
            re.icon_url = o.icon_url
            re.payment = o.payment
            re.platform = o.platform
            re.geo_targeting = o.geo_targeting
            re.rating = o.rating
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False  ##
            offers_list_new.append(o._id)  ##
            o.save()
    offers_list = OfferList.find_one(dict(_id=91))  ##
    if offers_list:  ##
        offers_list._id = 91  ##
        offers_list.offer_list = offers_list_new  ##
        offers_list.save()  ##
    else:  ##
        offers_list = OfferList(  ##
            dict(  ##
                _id=91,  ##
                offer_list=offers_list_new  ##
            )  ##
        )  ##
        offers_list.save()  ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new))  ##
    for offer_id in is_expired_offers:  ##
        offer = Offers.find_one(dict(_id=offer_id))  ##
        try:
            offer.is_expired = True  ##
            offer.save()
        except AttributeError:
            continue
예제 #17
0
def get_report():
    """
    """
    http = httplib2.Http()
    url = "https://api.hasoffers.com/Apiv3/json?NetworkId=adattract&Target=Affiliate_Offer&Method=findMyApprovedOffers&api_key=43bc7b535a0a37560334f2b0aea03783476887b9bd574a6ef5c4ca073e74462d"
    headers = {"Content-Type": "application/json"}
    response, content = http.request(url, 'GET', headers=headers)
    offers = yajl.loads(content)['response']['data']
    offers_list_new = []  ##
    offers_list_old = OfferList.find_one(dict(
        _id=138)).offer_list if OfferList.find_one(dict(_id=138)) else []  ##
    for k, v in offers.iteritems():
        click_url = "https://api.hasoffers.com/Apiv3/json?NetworkId=adattract&Target=Affiliate_Offer&Method=generateTrackingLink&api_key=43bc7b535a0a37560334f2b0aea03783476887b9bd574a6ef5c4ca073e74462d&offer_id=" + str(
            k)
        response, click_url = http.request(click_url, 'GET', headers=headers)
        try:
            click_url = yajl.loads(click_url)['response']['data']['click_url']
        except TypeError:
            continue

        country_url = "https://api.hasoffers.com/Apiv3/json?NetworkId=adattract&Target=Affiliate_Offer&Method=getTargetCountries&api_key=43bc7b535a0a37560334f2b0aea03783476887b9bd574a6ef5c4ca073e74462d&ids%5B%5D=" + str(
            k)
        response, country_url = http.request(country_url,
                                             'GET',
                                             headers=headers)
        try:
            country = yajl.loads(
                country_url)['response']['data'][0]['countries'].keys()
        except AttributeError:
            continue
        platform_url = "https://api.hasoffers.com/Apiv3/json?NetworkId=adattract&Target=Affiliate_OfferTargeting&Method=getRuleTargetingForOffer&api_key=43bc7b535a0a37560334f2b0aea03783476887b9bd574a6ef5c4ca073e74462d&offer_id=" + str(
            k)
        response, platform_url = http.request(platform_url,
                                              'GET',
                                              headers=headers)
        try:
            platform_url = yajl.loads(
                platform_url)['response']['data'][0]['rule']['name']
        except IndexError:
            platform_url = ''
        icon_url = "https://api.hasoffers.com/Apiv3/json?NetworkId=adattract&Target=Affiliate_OfferFile&Method=findAll&api_key=43bc7b535a0a37560334f2b0aea03783476887b9bd574a6ef5c4ca073e74462d&filters%5Boffer_id%5D=" + str(
            k)
        response, icon_banner = http.request(icon_url, 'GET', headers=headers)
        try:
            icon_url = yajl.loads(icon_banner)['response']['data'][
                'data'].values()[0]['OfferFile']['thumbnail']
            banner_url = yajl.loads(icon_banner)['response']['data'][
                'data'].values()[0]['OfferFile']['url']
        except (AttributeError, KeyError, TypeError) as e:
            icon_url = ''
            banner_url = ''
        if platform_url == 'Android':
            platform = '2'
        elif platform_url == 'iOS' or 'iPhone':
            platform = '1'
        else:
            continue
        o = dict(
            advertiser_id=138,
            is_api=True,
            offer_type=1,
            category_id=10,
            title=v['Offer']['name'],
            preview_url=v['Offer']['preview_url'],
            platform=platform,
            click_url=click_url +
            "&transaction_id={clickid}&aff_sub={aff_sub2}&affiliate_id={affid}&aff_sub2={aff_sub1}",  #done
            desciption=cgi.escape(v['Offer']['description']),
            total_cap=10000000,
            day_cap=10000000,
            month_cap=10000000,
            cap=dict(day=10000000, month=10000000, total=10000000),
            payment=float(v['Offer']['default_payout']) * 0.9,
            geo_targeting=country,
            conversions=0,
            revenue=float(v['Offer']['default_payout']),
            status='1',
            access_status='1',
            icon_url=icon_url,
            banner_url=banner_url)
        o = Offers(o)
        re = Offers.find_one(
            dict(title=o.title,
                 geo_targeting=o.geo_targeting,
                 platform=o.platform))  ##
        if re:
            offers_list_new.append(re._id)  ##
            re.is_expired = False  ##
            re.advertiser_id = o.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.title = o.title
            re.preview_url = o.preview_url
            re.platform = o.platform
            re.click_url = o.click_url
            re.icon_url = o.icon_url
            re.banner_url = o.banner_url
            re.desciption = o.desciption
            re.total_cap = o.total_cap
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.cap = o.cap
            re.payment = o.payment
            re.geo_targeting = o.geo_targeting
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False  ##
            offers_list_new.append(o._id)  ##
            o.save()
    offers_list = OfferList.find_one(dict(_id=138))  ##
    if offers_list:  ##
        offers_list._id = 138  ##
        offers_list.offer_list = offers_list_new  ##
        offers_list.save()  ##
    else:  ##
        offers_list = OfferList(  ##
            dict(  ##
                _id=138,  ##
                offer_list=offers_list_new  ##
            )  ##
        )  ##
        offers_list.save()  ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new))  ##
    for offer_id in is_expired_offers:  ##
        offer = Offers.find_one(dict(_id=offer_id))  ##
        try:
            offer.is_expired = True  ##
            offer.save()
        except AttributeError:
            continue
예제 #18
0
def get_report():
    """
    """
    http = httplib2.Http()
    url = "http://mapi.affle.co/publisher.php?cId=all&key=63389e65c6fe8cd5f7b2f8d12e698907"
    headers = {"Content-Type": "application/json"}
    response, content = http.request(url, 'GET', headers=headers)
    offers = yajl.loads(content)['data']
    offers_list_new = []  ##
    offers_list_old = OfferList.find_one(dict(
        _id=61)).offer_list if OfferList.find_one(dict(_id=61)) else []  ##
    for offer in offers:
        o = Offers(parse_offer(offer))
        re = Offers.find_one(
            dict(title=o.title,
                 geo_targeting=o.geo_targeting,
                 click_url=o.click_url))
        if re:
            offers_list_new.append(re._id)  ##
            re.advertiser_id = re.advertiser_id
            re.is_api = o.is_api
            re.offer_type = o.offer_type
            re.category_id = o.category_id
            re.title = o.title
            re.platform = o.platform
            # re.package_name = o.package_name
            # re.mini_version = o.mini_version
            re.click_url = o.click_url
            re.banner_url = o.banner_url
            re.preview_url = o.preview_url
            re.total_cap = o.total_cap
            re.day_cap = o.day_cap
            re.month_cap = o.month_cap
            re.cap = o.cap
            re.payment = o.payment
            re.geo_targeting = o.geo_targeting
            re.create_time = o.create_time
            re.conversions = o.conversions
            re.revenue = o.revenue
            re.status = o.status
            re.access_status = o.access_status
            re.is_expired = False  ##
            re.save()
        else:
            o._id = _gid('ApiKey')
            o.is_expired = False  ##
            offers_list_new.append(o._id)  ##
            o.save()
    offers_list = OfferList.find_one(dict(_id=61))  ##
    if offers_list:  ##
        offers_list._id = 61  ##
        offers_list.offer_list = offers_list_new  ##
        offers_list.save()  ##
    else:  ##
        offers_list = OfferList(  ##
            dict(  ##
                _id=61,  ##
                offer_list=offers_list_new  ##
            )  ##
        )  ##
        offers_list.save()  ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new))  ##
    for offer_id in is_expired_offers:  ##
        offer = Offers.find_one(dict(_id=offer_id))  ##
        try:
            offer.is_expired = True  ##
            offer.save()
        except AttributeError:
            continue
예제 #19
0
def get_report():
    """
    """
    http = httplib2.Http()
    url = "http://feed.appthis.com/feed/v1?api_key=2b749940922e74c65292a6da90e5dc01&format=json"
    headers = {"Content-Type": "application/json"}
    response, content = http.request(url, 'GET', headers=headers)
    offers = yajl.loads(content)['offers']
    offers_list_new = []  ##
    offers_list_old = OfferList.find_one(dict(
        _id=86)).offer_list if OfferList.find_one(dict(_id=86)) else []  ##
    for k, v in offers.iteritems():
        for campaign in v['campaigns']:
            if not v['icon_url'].startswith('http'):
                v['icon_url'] = 'http:' + v['icon_url']
            if campaign['platform'] == 'Android':
                campaign['platform'] = '2'
            if campaign['platform'] == 'iPhone':
                campaign['platform'] = '1'
            o = dict(
                advertiser_id=86,
                is_api=True,
                offer_type=1,
                category_id=10,
                title=v['name'],
                platform=campaign['platform'],
                package_name=v['android_package_name'],
                click_url=v['tracking_url'] +
                "?clickid={clickid}&source={affid}&source2={aff_sub2}",  #done
                icon_url=v['icon_url'],
                desciption=v['description'],
                total_cap=10000000,
                day_cap=10000000,
                month_cap=10000000,
                cap=dict(day=10000000, month=10000000, total=10000000),
                payment=float(campaign['payout']) * 0.9,
                geo_targeting=campaign['countries'],
                conversions=0,
                revenue=float(campaign['payout']),
                status='1',
                access_status='1')
            o = Offers(o)
            re = Offers.find_one(
                dict(title=o.title,
                     geo_targeting=o.geo_targeting,
                     platform=o.platform))
            if re:
                offers_list_new.append(re._id)  ##
                re.is_expired = False  ##
                re.advertiser_id = o.advertiser_id
                re.is_api = o.is_api
                re.offer_type = o.offer_type
                re.category_id = o.category_id
                re.title = o.title
                re.platform = o.platform
                re.package_name = o.package_name
                re.click_url = o.click_url
                re.icon_url = o.icon_url
                re.desciption = o.desciption
                re.total_cap = o.total_cap
                re.day_cap = o.day_cap
                re.month_cap = o.month_cap
                re.cap = o.cap
                re.payment = o.payment
                re.geo_targeting = o.geo_targeting
                re.conversions = o.conversions
                re.revenue = o.revenue
                re.status = o.status
                re.access_status = o.access_status
                re.save()
            else:
                o._id = _gid('ApiKey')
                o.is_expired = False  ##
                offers_list_new.append(o._id)  ##
                o.save()
    offers_list = OfferList.find_one(dict(_id=86))  ##
    if offers_list:  ##
        offers_list._id = 86  ##
        offers_list.offer_list = offers_list_new  ##
        offers_list.save()  ##
    else:  ##
        offers_list = OfferList(  ##
            dict(  ##
                _id=86,  ##
                offer_list=offers_list_new  ##
            )  ##
        )  ##
        offers_list.save()  ##
    is_expired_offers = list(set(offers_list_old) - set(offers_list_new))  ##
    for offer_id in is_expired_offers:  ##
        offer = Offers.find_one(dict(_id=offer_id))  ##
        try:
            offer.is_expired = True  ##
            offer.save()
        except AttributeError:
            continue