本文整理汇总了Python中admitad.items.base.Item类的典型用法代码示例。如果您正苦于以下问题:Python Item类的具体用法?Python Item怎么用?Python Item使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, **kwargs):
"""
Args:
campaign (list of int)
language (str)
order_by (str)
limit (int)
offset (int)
"""
ordering = {
'order_by': kwargs.get('order_by', None),
'available': self.ORDERING
}
filtering = {
'filter_by': kwargs,
'available': {
'campaign': lambda x: Item.sanitize_integer_array(x, 'campaign', True),
'language': lambda x: Item.sanitize_string_value(x, 'language', 2, 2, True),
}
}
return self.transport.get() \
.set_pagination(**kwargs) \
.set_ordering(ordering) \
.set_filtering(filtering) \
.request(url=self.URL)
示例2: get
def get(self, **kwargs):
"""
Args:
campaign (int)
website (int)
limit (int)
offset (int)
order_by (list of str)
"""
ordering = {
'order_by': kwargs.get('order_by', []),
'available': self.ORDERING
}
filtering = {
'filter_by': kwargs,
'available': {
'campaign': lambda x: Item.sanitize_integer_value(x, 'campaign', blank=True),
'website': lambda x: Item.sanitize_integer_value(x, 'campaign', blank=True),
}
}
return self.transport.get() \
.set_pagination(**kwargs) \
.set_ordering(ordering) \
.set_filtering(filtering) \
.request(url=self.URL)
示例3: update
def update(self, optcode_id, **kwargs):
data = Item.sanitize_fields(self.UPDATE_FIELDS, **kwargs)
request_data = {
'url': self.UPDATE_URL,
'optcode_id': Item.sanitize_id(optcode_id),
}
return self.transport.post().set_data(data).request(**request_data)
示例4: test_sanitize_float_value
def test_sanitize_float_value(self):
self.assertEqual(Item.sanitize_float_value(1, '', False), 1)
self.assertEqual(Item.sanitize_float_value(0, '', False), 0)
self.assertEqual(Item.sanitize_float_value('12', '', False), '12')
self.assertEqual(Item.sanitize_float_value('3.14', '', False), '3.14')
self.assertEqual(Item.sanitize_float_value(3.14, '', False), 3.14)
self.assertEqual(Item.sanitize_float_value(None, '', True), None)
with self.assertRaises(ValueError):
Item.sanitize_float_value(None, '', False)
Item.sanitize_float_value('foo', '', False)
示例5: test_sanitize_long_date
def test_sanitize_long_date(self):
self.assertEqual(Item.sanitize_long_date(None, '', True), None)
self.assertEqual(Item.sanitize_long_date(datetime(2020, 1, 1, 11, 20, 36), '', False), '01.01.2020 11:20:36')
self.assertEqual(Item.sanitize_long_date('01.01.2020 11:20:36', '', False), '01.01.2020 11:20:36')
with self.assertRaises(ValueError):
Item.sanitize_long_date(None, '', False)
Item.sanitize_long_date('01/01/2020', '', True)
Item.sanitize_long_date('01.01.2020 11/22/22', '', False)
示例6: comment
def comment(self, ticket_id, **kwargs):
"""
Args:
ticket_id (int)
text (str)
"""
request_data = {
'url': self.COMMENT_URL,
'ticket_id': Item.sanitize_id(ticket_id)
}
data = Item.sanitize_fields(self.COMMENT_FIELDS, **kwargs)
return self.transport.post().set_data(data).request(**request_data)
示例7: getOne
def getOne(self, _id, c_id, **kwargs):
"""
Here _id is a website id and c_id is a campaign id
Args:
_id (int)
c_id (int)
"""
request_data = {
'url': self.SINGLE_URL,
'website_id': Item.sanitize_id(_id),
'campaign_id': Item.sanitize_id(c_id)
}
return self.transport.get().request(**request_data)
示例8: get
def get(self, campaign_id, website_id, **kwargs):
"""
Args:
campaign_id (int)
website_id (int)
limit (int)
offset (int)
"""
request_data = {
'url': self.URL,
'campaign_id': Item.sanitize_id(campaign_id),
'website_id': Item.sanitize_id(website_id),
}
return self.transport.get().set_pagination(**kwargs).request(**request_data)
示例9: test_sanitize_date
def test_sanitize_date(self):
self.assertEqual(Item.sanitize_date(None, '', True), None)
self.assertEqual(Item.sanitize_date(datetime(2020, 1, 1), '', False), '01.01.2020')
self.assertEqual(Item.sanitize_date(date(2020, 1, 1), '', False), '01.01.2020')
self.assertEqual(Item.sanitize_date('01.01.2020', '', False), '01.01.2020')
with self.assertRaises(ValueError):
Item.sanitize_date(None, '', False)
Item.sanitize_date('01/01/2020', '', True)
示例10: create
def create(self, attachments, **kwargs):
"""
Args:
attachments (list of str)
campaign (int)
website (int)
order_id (str)
order_date (date)
order_price (float)
appeal_id (str)
comment (str)
"""
data = Item.sanitize_fields(self.CREATE_FIELDS, **kwargs)
files = [('attachment', open(item, 'rb')) for item in Item.sanitize_string_array(attachments, 'attachments')]
return self.transport.post().set_data(data).set_files(files).request(url=self.CREATE_URL)
示例11: disconnect
def disconnect(self, c_id, w_id, **kwargs):
"""
Disconnect an advertising campaign from a website
Here w_id is a website id and c_id is a campaign id
Args:
c_id (int)
w_id (int)
"""
request_data = {
'url': self.DISCONNECT_URL,
'campaign_id': Item.sanitize_id(c_id),
'website_id': Item.sanitize_id(w_id)
}
return self.transport.post().request(**request_data)
示例12: get
def get(self, **kwargs):
"""
Args:
campaign (id)
website (id)
status (string)
start_date (date)
end_date (date)
appeal_id (string)
appeal_status (string)
limit (int)
offset (int)
"""
filtering = {
'filter_by': kwargs,
'available': {
'campaign': lambda x: Item.sanitize_integer_value(x, 'campaign', blank=True),
'website': lambda x: Item.sanitize_integer_value(x, 'website', blank=True),
'status': lambda x: Item.sanitize_string_value(x, 'status', blank=True),
'start_date': lambda x: Item.sanitize_string_value(x, 'start_date', blank=True),
'end_date': lambda x: Item.sanitize_string_value(x, 'end_date', blank=True),
'appeal_id': lambda x: Item.sanitize_string_value(x, 'appeal_id', blank=True),
'appeal_status': lambda x: Item.sanitize_string_value(x, 'appeal_status', blank=True),
}
}
return self.transport.get() \
.set_filtering(filtering) \
.set_pagination(**kwargs) \
.request(url=self.URL)
示例13: update
def update(self, retag_id, **kwargs):
"""
Args:
retag_id (int)
level (int)
active (bool)
script (str)
comment (str)
"""
request_data = {
'url': self.UPDATE_URL,
'retag_id': Item.sanitize_id(retag_id)
}
data = Item.sanitize_fields(self.UPDATE_FIELDS, **kwargs)
return self.transport.post().set_data(data).request(**request_data)
示例14: create
def create(self, website_id, campaign_id, **kwargs):
"""
Args:
website_id (int)
campaign_id (int)
ulp (list of str)
subid (str)
"""
data = Item.sanitize_fields(self.CREATE_FIELDS, **kwargs)
request_data = {
'url': self.CREATE_URL,
'website_id': Item.sanitize_id(website_id),
'campaign_id': Item.sanitize_id(campaign_id),
}
return self.transport.get().set_data(data).request(**request_data)
示例15: get
def get(self, link, **kwargs):
"""
Args:
link (str)
"""
data = Item.sanitize_fields(self.GET_FIELDS, link=link)
return self.transport.get().set_data(data).request(url=self.URL)