def get(self): spec = {"status": '1', "is_api": {"$ne": True}} fields = dict(_id=1, title=1, payment=1, access_status=1, preview_url=1) _type = self.get_argument('_type') country = self.get_arguments('countries[]') if country: spec.update(dict(geo_targeting=country)) PriceModel = self.get_argument('price_model') if PriceModel: spec.update(dict(price_model=PriceModel)) category = self.get_argument('categories') if category: spec.update(dict(category=category)) min_payout = self.get_argument('payoutMin', 0) max_payout = self.get_argument('payoutMax', 10000) spec.update( dict(payment={ '$gte': float(min_payout), '$lte': float(max_payout) })) limit = int(self.get_argument('limit', 20)) page = int(self.get_argument('page', 1)) id_or_name = self.get_argument('offerSearch') if id_or_name: if id_or_name.isdigit(): spec.update(dict(_id=int(id_or_name))) else: spec.update(dict(title=id_or_name)) if _type == 'need_approived': access_status = self.get_argument('access_status') if access_status: spec.update(dict(access_status=access_status)) offers = Offers.find(spec, fields, sort=[('_id', -1)]) offers = filter(self.filter_offer, offers) elif _type == 'applied': offers = Offers.find(spec, fields, sort=[('_id', -1)]) offers = filter(self.filter_offer_apply, offers) application_status = self.get_argument('approvalStatus') if application_status: offers = filter( lambda offer: offer['apply_status'] == application_status, offers) offers_count = len(offers) offers = offers[limit * (page - 1):limit * page] self.finish(dict(offers=offers, offers_count=offers_count))
def post(self, offer_id): kw = Offers.get_parm(self, type='modify') include_geos = kw.get('geo_targeting') exclude_geos = kw.get('exclude_geo_targeting') geos = c().countries if include_geos: for geo in include_geos: geos.pop(geo) kw['exclude_geo_targeting'] = geos.keys() elif not exclude_geos: kw['geo_targeting'] = geos.keys() Offers._update(offer_id, **kw) self.redirect("/offers/manage")
def post(self): kw = Offers.get_parm(self) include_geos = kw.get('geo_targeting') exclude_geos = kw.get('exclude_geo_targeting') geos = c().countries if include_geos: for geo in include_geos: geos.pop(geo) kw['exclude_geo_targeting'] = geos.keys() elif not exclude_geos: kw['geo_targeting'] = geos.keys() offer = Offers._save(**kw) self.redirect("/offer_affiliate?offer_id={}".format(offer._id))
def get(self): user_id = self.current_user_id affiliate = Affiliate.find_one(dict(user_id=int(user_id))) user = User.find_one(dict(_id=int(affiliate.account_manager))) lastest_offers = Offers.sort_limit( [('_id', -1)], 10, dict(status={'$ne': '0'}, is_api={'$ne': True})) deloffers = [] for offer in lastest_offers: off_aff = OfferAffiliate.find_one( dict(offer_id=int(offer._id), affiliate_id=user_id, deleted=False)) if off_aff: if off_aff.payout: offer.payment = off_aff.payout if offer.access_status == '0' and off_aff.status != '1': deloffers.append(offer) else: if offer.access_status == '0': deloffers.append(offer) for i in deloffers: lastest_offers.remove(i) offer_infos = OfferInfo.sort_limit( [('amount', -1)], 10, dict(affiliate_id=user_id)) # feature offers condition = [] for i in offer_infos: condition.append({'_id': i.offer_id}) if condition: high_income_offers = Offers.find( {'$or': condition, 'status': {'$ne': '0'}, 'is_api': {'$ne': True}}) deloffers = [] for offer in high_income_offers: off_aff = OfferAffiliate.find_one( dict(offer_id=int(offer._id), affiliate_id=user_id, deleted=False)) if off_aff: if off_aff.payout: offer.payment = off_aff.payout if offer.access_status == '0' and off_aff.status != '1': deloffers.append(offer) else: if offer.access_status == '0': deloffers.append(offer) for i in deloffers: high_income_offers.remove(i) else: high_income_offers = [] self.render( account_manager=user, lastest_offers=lastest_offers, high_income_offers=high_income_offers, )
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
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)
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)
def get(self): id_or_name = self.get_argument('q') spec = dict() if id_or_name.isdigit(): spec.update({'_id': int(id_or_name)}) else: spec.update({'title': {'$regex': id_or_name, '$options': "$i"}}) offers = Offers.find(spec, {'title': 1}, limit=10) offers = [{'first_name': i._id, 'last_name': i.title} for i in offers] self.finish(json.dumps(offers))
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)
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)
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")
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
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))
def post(self): content = loads(self.request.body) status = content.get("status", "") limit = int(content.get("limit")) page = int(content.get("page")) skip = (page - 1) * limit cats = Category.find(dict( status={"$ne": '0'} if not status or status == '0' else status), skip=skip, limit=limit) cat_count = Category.count(dict( status={"$ne": '0'} if not status or status == '0' else status), skip=skip, limit=limit) for cat in cats: cat['offer_count'] = Offers.count(dict(category=str(cat._id))) cat.status = 'Active' if cat.status == '1' else 'Pending' self.finish(dict(cat=cats, cat_count=cat_count))
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, )
def get(self, ad_id): ad = Advertisers.find_one(dict(user_id=int(ad_id))) ad_user = User.find_one(dict(_id=int(ad_id))) if ad_user: ad['_id'] = ad_user._id ad['name'] = ad_user.account ad['email'] = ';'.join(ad_user.email) ad['skype_id'] = ad_user.skype_id bd = User.find_one(dict(_id=ad.account_manager)) ad['bd'] = bd.account if bd else '' pm = User.find_one(dict(_id=ad.pm)) ad['pm'] = pm.account if pm else '' offers_count = Offers.count(dict(advertiser_id=ad_user._id)) ad['offers_count'] = offers_count status_map = {'0': 'Deleted', '1': 'Active', '2': 'Paused'} ad['status'] = status_map.get(ad.status) ad['white_list'] = ','.join(ad.white_list) if ad.white_list else '' self.render(advertiser=ad) else: self.write('The advertiser not exist!')
def get(self): offer_spce = dict(status={"$ne": 0}, is_api={"$ne": True}) offers = Offers.find(offer_spce, dict(_id=1, title=1)) affiliate_spec = dict(status={"$ne": 0}) affiliates = Affiliate.find(affiliate_spec, dict(user_id=1)) for aff in affiliates: user = User.find_one(dict(_id=int(aff.user_id)), dict(_id=1, account=1)) if not user: continue aff['_id'] = user._id aff['name'] = user.account advertiser_spec = dict(status={"$ne": 0}) advertisers = Advertisers.find(advertiser_spec, dict(user_id=1)) for ad in advertisers: user = User.find_one(dict(_id=int(ad.user_id)), dict(_id=1, account=1)) if not user: continue ad['_id'] = user._id ad['name'] = user.account categories = Category.find(dict(status={"$ne": 0}), dict(_id=1, name=1)) ams = User.find(dict(role_id=Role.am()._id, deleted=False), dict(_id=1, account=1, role_id=1)) ams = [am for am in ams if am.role_id and am._role == 'AM'] bds = User.find(dict(role_id=Role.bd()._id, deleted=False), dict(_id=1, account=1, role_id=1)) bds = [bd for bd in bds if bd.role_id and bd._role == 'BD'] self.finish( dict(offers=offers, affiliates=affiliates, advertisers=advertisers, categories=categories, ams=ams, bds=bds))
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)
def get(self, action): obj_list = [] if action == 'affiliate': offer_id = self.get_argument('offer_id') off_affs = OAffiliates._query(offer_ids=[offer_id]) obj_ids = [off_aff.affiliate_id for off_aff in off_affs] affilate_extends = Affiliate.find( dict(account_manager={"$ne": ''}, status={'$ne': '0'})) objs = User.find( dict(_id={ "$in": [ int(aff.user_id) for aff in affilate_extends if aff.account_manager ] }, deleted=False)) res = dict(affiliates=obj_list) elif action == 'offers': affiliate_id = self.get_argument('affiliate_id') off_affs = OAffiliates._query(affiliate_id=affiliate_id) obj_ids = [off_aff.offer_id for off_aff in off_affs] objs = Offers.find({ 'status': { '$ne': '0' }, 'is_api': { "$ne": True } }) res = dict(offers=obj_list) for obj in objs: if int(obj._id) not in obj_ids: obj_list.append(obj) self.finish(res)
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
def get(self): email = self.get_argument('email') pagenum = self.get_argument('pagenum', 100) page = self.get_argument('page', 1) status = self.get_argument('status', 'all', strip=True) # myOffers # all user = User.find_one(dict(email=email, deleted=False)) if user: aff = Affiliate.find_one( dict(user_id=user._id, status={'$ne': '0'})) if aff: url = "http://tracks.leadhug.com/lh/click?offer_id={0}&affiliate_id={1}&click_id={{clickid}}&aff_sub1={{aff_sub1}}" if status == "all": spec = {'is_api': True, 'is_expired': False} offers = Offers.find(spec, sort=[('_id', -1)], limit=int(pagenum), skip=(int(page) - 1) * int(pagenum)) if page == 1: to_api_offers = Offers.find(dict(to_api=True, status='1'), sort=[('_id', -1)]) else: to_api_offers = [] all_offers = offers + to_api_offers else: spec = {"status": '1'} off_affs = OfferAffiliate.find( dict(affiliate_id=int(aff.user_id), status='1', deleted=False)) offer_ids = [int(off_aff.offer_id) for off_aff in off_affs] spec.update(dict(_id={'$in': offer_ids})) all_offers = Offers.find(spec, sort=[('_id', -1)]) for offer in all_offers: off_aff = OfferAffiliate.find_one( dict(offer_id=int(offer._id), affiliate_id=aff.user_id, deleted=False)) if off_aff.payout: offer.payment = off_aff.payout for offer in all_offers: offer['click_url'] = url.format(offer._id, aff.user_id) offer['_id'] = int(offer['_id']) if offer['platform'] == '1': offer['platform'] = 'ios' if offer['platform'] == '2': offer['platform'] = 'android' del offer['revenue'] del offer['clicks'] del offer['advertiser_id'] del offer['user'] del offer['conversions'] del offer['access_status'] del offer['last_update'] del offer['price_model'] del offer['status'] del offer['mini_version'] del offer['exclude_geo_targeting'] del offer['offer_type'] del offer['black_ip'] del offer['traffic_time'] del offer['create_time'] del offer['root'] del offer['is_api'] # del offer['offer_type'] del offer['category_id'] del offer['tag'] del offer['rating'] del offer['restrictions'] del offer['is_expired'] del offer['to_api'] self.finish(json_encode(all_offers)) else: self.finish('email invalid!') else: self.finish("email not found!")
def get(self): filter = loads(self.get_argument('filter', '')) offer_id = filter.get('offer_id') is_api = filter.get('is_api') status = filter.get('status') category = filter.get('category') price_model = filter.get('price_model') advertiser = filter.get('advertiser') country = filter.get('geo', '') payment_min = filter.get('payout_min') payment_max = filter.get('payout_mix') is_api = True if is_api == '1' else {"$ne": True} query = {"is_api": is_api} if offer_id: query["_id"] = int(offer_id) if status: query["status"] = status if category: query["category"] = category if price_model: query["price_model"] = price_model if advertiser: query["advertiser"] = advertiser if country: country_list = country.split(',') query["geo_targeting"] = country if len(country_list) == 1 else { '$in': country_list } if payment_max or payment_min: query["payment"] = {} if payment_min: query["payment"]["$gte"] = float(payment_min) if payment_max: query["payment"]["$lte"] = float(payment_max) offers = Offers.find(query, sort=[('_id', 1)]) fields = [ '_id', 'name', 'category', 'payout_model', 'advertiser', 'payout', 'revenue', 'preview_url', 'geo_count', 'clicks', 'conversions', 'day_cap', 'total_cap' ] result_offers = [] for offer in offers: if offer.status == '0': offer.status = 'Paused' elif offer.status == '1': offer.status = 'Active' else: offer.status = 'Pending' if offer.price_model == '1': offer.price_model = 'CPA' elif offer.price_model == '2': offer.price_model = 'CPS' elif offer.price_model == '3': offer.price_model = 'CPC' if offer.advertiser_id: ad = User.find_one(dict(_id=int(offer.advertiser_id))) offer['advertiser'] = ad.account if offer.category_id: category = Category.find_one(dict(_id=int(offer.category_id))) offer['category'] = category.name off_tmp = dict(_id=offer._id, name=offer.title, category=offer.get('category'), payout_model=offer.price_model, advertiser=offer.get('advertiser'), payout=offer.payment, revenue=offer.revenue, preview_url=offer.preview_url, geo_count=len(offer.geo_targeting), clicks=offer.clicks, conversions=offer.conversions, day_cap=offer.day_cap, total_cap=offer.total_cap) result_offers.append(off_tmp) with open('offer.csv', 'wb') as f: f.write(codecs.BOM_UTF8) fieldnames = fields dict_writer = csv.DictWriter(f, fieldnames=fieldnames) dict_writer.writeheader() dict_writer.writerows(result_offers) file = open('offer.csv', 'r') self.set_header('Content-Type', 'application/octet-stream') self.set_header('Content-Disposition', 'attachment; filename=offer.csv') self.write(file.read())
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()
def get(self): spec = {"status": '1'} is_api = self.get_argument('is_api') if is_api == '0': spec.update(dict(is_api={"$ne": True})) country = self.get_arguments('countries[]') if country: spec.update(dict(geo_targeting=country)) PriceModel = self.get_argument('price_model') if PriceModel: spec.update(dict(price_model=PriceModel)) category = self.get_argument('categories') if category: spec.update(dict(category=category)) min_payout = self.get_argument('payoutMin', 0) max_payout = self.get_argument('payoutMax', 10000) spec.update( dict(payment={ '$gte': float(min_payout), '$lte': float(max_payout) })) limit = int(self.get_argument('limit', 20)) page = int(self.get_argument('page', 1)) off_affs = OfferAffiliate.find( dict(affiliate_id=int(self.current_user_id), status='1', deleted=False)) offer_ids = [int(off_aff.offer_id) for off_aff in off_affs] spec.update(dict(_id={'$in': offer_ids})) offers = Offers.find(spec, sort=[('_id', -1)]) url = "tracks.leadhug.com/lh/click?offer_id={0}&affiliate_id={1}&click_id={{clickid}}&aff_sub1={{aff_sub1}}" for offer in offers: off_aff = OfferAffiliate.find_one( dict(offer_id=int(offer._id), affiliate_id=self.current_user_id, deleted=False)) if off_aff.payout: offer.payment = off_aff.payout offer['tracking_link'] = url.format(offer._id, self.current_user_id) conversions = off_aff.get('conversions', 0) if off_aff.get( 'conversions', 0) else 0 clicks = off_aff.get('clicks', 0) if off_aff.get('clicks', 0) else 0 cost = off_aff.get('cost', 0) if off_aff.get('cost', 0) else 0 offer['conversions'] = conversions offer['clicks'] = clicks offer['CR'] = float(conversions) / float( clicks) * 100 if clicks else 0 offer['EPC'] = float(cost) / float(clicks) * 100 if clicks else 0 offer['total'] = cost offers_count = len(offers) offers = offers[limit * (page - 1):limit * page] self.finish(dict(offers=offers, offers_count=offers_count))
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
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
def get(self): e_models = EmailModel.find({'deleted': False}) active_traffic_time = DateTime.get_day(6) offers = Offers.query(active_traffic_time) self.render(e_models=e_models, offers=offers)
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
def get(self): affiliate_id = self.current_user_id off_affs = OfferAffiliate._query(affiliate_id=affiliate_id) offer_ids = [off_aff.offer_id for off_aff in off_affs] offers = Offers.find(dict(_id={'$in': offer_ids})) self.render(countries=_c().countries, offers=offers)
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