-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.py
More file actions
37 lines (27 loc) · 1.38 KB
/
item.py
File metadata and controls
37 lines (27 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from math import ceil
class Item(object):
personal_receipt_ids = [10, 13]
not_registered_ids = [2, 4]
def __init__(self, item_info, shipping_options):
self.item_info = item_info
self.shipping_options = shipping_options
def get(self, attr_name):
return getattr(self.item_info, 'it' + attr_name[0].upper() + attr_name[1:])
def get_url(self):
return 'http://allegro.pl/ShowItem2.php?item=%d' % self.get('id')
def get_lowest_shipping_price(self, items_count, skip_not_registered=False):
if self.get('quantity') < items_count:
return None
min_price = None
for shipping_option in self.shipping_options:
if shipping_option.postageId in self.personal_receipt_ids or (skip_not_registered and shipping_option.postageId in self.not_registered_ids):
# don't include personal receipts and not registered
continue
if shipping_option.postageFreeShipping:
current_price = 0
else:
parcels_count = ceil(float(items_count) / shipping_option.postagePackSize)
current_price = parcels_count * shipping_option.postageAmount + (items_count - parcels_count) * shipping_option.postageAmountAdd
if min_price is None or current_price < min_price:
min_price = current_price
return min_price