def app_stat_from_xml(stat_element): if stat_element is None: return None return AppStat(id=get_attr(stat_element, 'id', int), shows_overall=get_value(stat_element, 'shows-overall', int), actions_overall=get_value(stat_element, 'actions-overall', int), dau_average=get_value(stat_element, 'dau-average', float), dau_day0=get_value(stat_element, 'dau-day0', int), dau_day1=get_value(stat_element, 'dau-day1', int), dau_day2=get_value(stat_element, 'dau-day2', int), dau_day3=get_value(stat_element, 'dau-day3', int), dau_day4=get_value(stat_element, 'dau-day4', int), dau_day5=get_value(stat_element, 'dau-day5', int), dau_day6=get_value(stat_element, 'dau-day6', int))
def app_from_xml(app_element): if app_element is None: return None return App(id=get_attr(app_element, 'id', int), title=get_value(app_element, 'title'), secret=get_value(app_element, 'secret'), user_id=get_value(app_element, 'user-id', int), user=user_from_xml(get_child(app_element, 'user')), platform=get_value(app_element, 'platform'), callback=get_value(app_element, 'callback'), url=get_value(app_element, 'url'), deleted=get_value(app_element, 'deleted', bool), creation_time=datetime_from_api(get_value(app_element, 'creation-time')), d=get_value(app_element, 'd', float), t=get_value(app_element, 't', float), stats=app_stat_from_xml(get_child(app_element, 'stats')))
def transaction_from_xml(transaction_element): if transaction_element is None: return None return Transaction(id=get_attr(transaction_element, 'id', int), diff=get_value(transaction_element, 'diff', float), balance=get_value(transaction_element, 'balance', float), description=get_value(transaction_element, 'description'), type=get_value(transaction_element, 'type'), creation_time=datetime_from_api(get_value(transaction_element, 'creation-time')), end_time=datetime_from_api(get_value(transaction_element, 'end-time')))
def action_from_xml(action_element): if action_element is None: return None return Action(id=get_attr(action_element, 'id', int), performer_id=get_value(action_element, 'performer-id', int), performer=performer_from_xml(get_child(action_element, 'performer')), offer_id=get_value(action_element, 'offer-id', int), order=order_from_xml(get_child(action_element, 'order')), app=app_from_xml(get_child(action_element, 'app')), done=get_value(action_element, 'done', bool), deleted=get_value(action_element, 'deleted', bool), creation_time=datetime_from_api(get_value(action_element, 'creation-time')), approve_time=datetime_from_api(get_value(action_element, 'approve-time')), attempts=get_value(action_element, 'attempts'))
def performer_from_xml(performer_element): if performer_element is None: return None return Performer(id=get_attr(performer_element, 'id', int), ext_id=get_value(performer_element, 'ext-id'), platform=get_value(performer_element, 'platform'), creation_time=datetime_from_api(get_value(performer_element, 'creation-time')), inviter=performer_from_xml(get_child(performer_element, 'inviter')), male=get_value(performer_element, 'male', bool), year=get_value(performer_element, 'year', int), city=get_value(performer_element, 'city'))
def banner_from_xml(banner_element): if banner_element is None: return None return Banner(id=get_attr(banner_element, 'id', int), size=banner_size_from_xml(get_child(banner_element, 'banner-size')), mime_type=get_value(banner_element, 'mime-type'), image=get_value(banner_element, 'image'))
def banner_size_from_xml(size_element): if size_element is None: return None return BannerSize(id=get_attr(size_element, 'id', int), width=get_value(size_element, 'width', int), height=get_value(size_element, 'height', int), disabled=get_value(size_element, 'disabled', bool))
def order_stat_from_xml(stat_element): if stat_element is None: return None return OrderStat(id=get_attr(stat_element, 'id', int), shows_overall=get_value(stat_element, 'shows-overall', int), actions_overall=get_value(stat_element, 'actions-overall', int))
def order_from_xml(order_element): if order_element is None: return None return Order(id=get_attr(order_element, 'id', int), user=user_from_xml(get_child(order_element, 'user')), user_id=get_value(order_element, 'user-id', int), cpa=get_value(order_element, 'cpa', float), disabled=get_value(order_element, 'disabled', bool), paused=get_value(order_element, 'paused', bool), creation_time=datetime_from_api(get_value(order_element, 'creation-time')), account=account_from_xml(get_child(order_element, 'account')), # Common offer fields offer_id=get_value(order_element, 'offer-id', int), title=get_value(order_element, 'title'), url=get_value(order_element, 'url'), auto_approve=get_value(order_element, 'auto-approve', bool), reentrant=get_value(order_element, 'reentrant', bool), type=get_value(order_element, 'type'), stats=order_stat_from_xml(get_child(order_element, 'stats')), # Regular offer fields description=get_value(order_element, 'description'), image=get_value(order_element, 'image'), # Banner offer fields banners=map(banner_from_xml, order_element.xpath('./banners/banner')), # Video offer fields video_url=get_value(order_element, 'video-url'), # Targeting fields male=get_value(order_element, 'male', bool), min_age=get_value(order_element, 'min-age', int), max_age=get_value(order_element, 'max-age', int), min_hour=get_value(order_element, 'min-hour', int), max_hour=get_value(order_element, 'max-hour', int), city_filter_type=get_value(order_element, 'city-filter-type'), cities=map(city_from_xml, order_element.xpath('./cities/city')), app_filter_type=get_value(order_element, 'app-filter-type'), apps=map(app_from_xml, order_element.xpath('./apps/app')))
def settings_from_xml(settings_element): if settings_element is None: return None return Settings( m=get_value(settings_element, 'm', float), q=get_value(settings_element, 'q', float), c_min=get_value(settings_element, 'c-min', float))
def withdrawal_from_xml(withdrawal_element): if withdrawal_element is None: return None return Withdrawal(id=get_attr(withdrawal_element, 'id', int), amount=get_value(withdrawal_element, 'amount', float), timestamp=datetime_from_api(get_value(withdrawal_element, 'timestamp')), done=get_value(withdrawal_element, 'done', bool))
def account_from_xml(account_element): if account_element is None: return None return Account(id=get_attr(account_element, 'id', int), balance=get_value(account_element, 'balance', float), allow_negative_balance=get_value(account_element, 'allow-negative-balance', bool))
def user_stat_from_xml(stat_element): if stat_element is None: return None return UserStat(id=get_attr(stat_element, 'id', int), payments=get_value(stat_element, 'payments', float), unpaid_actions=get_value(stat_element, 'unpaid-actions', int))
def user_from_xml(user_element): if user_element is None: return None return User(id=get_attr(user_element, 'id', int), email=get_value(user_element, 'email'), password_hash=get_value(user_element, 'password-hash'), first_name=get_value(user_element, 'first-name'), last_name=get_value(user_element, 'last-name'), organization=get_value(user_element, 'organization'), phone=get_value(user_element, 'phone'), source_url=get_value(user_element, 'source-url'), messenger_type=get_value(user_element, 'messenger-type'), messenger_uid=get_value(user_element, 'messenger-uid'), confirmed=get_value(user_element, 'confirmed', bool), blocked=get_value(user_element, 'blocked', bool), register_time=datetime_from_api(get_value(user_element, 'register-time')), apps=map(app_from_xml, user_element.xpath('./apps/app')), orders=map(order_from_xml, user_element.xpath('./orders/order')), roles=map(role_from_xml, user_element.xpath('./roles/role')), referrer=get_value(user_element, 'referrer', int), referrals=map(referral_from_xml, user_element.xpath('./referrals/referral')), revenue=get_value(user_element, 'revenue'), customer_secret=get_value(user_element, 'customer-secret'), customer_account=account_from_xml(get_child(user_element, 'customer-account')), developer_account=account_from_xml(get_child(user_element, 'developer-account')), stats=user_stat_from_xml(get_child(user_element, 'stats')))
def city_from_xml(city_element): if city_element is None: return None return City(id=get_attr(city_element, 'id', int), name=get_value(city_element, 'name'), disabled=get_value(city_element, 'disabled', bool))