-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathproduct.py
More file actions
201 lines (164 loc) · 5.36 KB
/
product.py
File metadata and controls
201 lines (164 loc) · 5.36 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from typing import List, Optional
import attrs
from web_poet import Returns
from zyte_common_items.components import (
AdditionalProperty,
AggregateRating,
Brand,
Breadcrumb,
Gtin,
Image,
)
from zyte_common_items.fields import auto_field
from zyte_common_items.items import Product, ProductMetadata, ProductVariant
from zyte_common_items.processors import (
brand_processor,
breadcrumbs_processor,
description_html_processor,
description_processor,
gtin_processor,
list_processor,
price_processor,
rating_processor,
simple_price_processor,
string_processor,
)
from .base import BasePage, Page
from .mixins import DescriptionMixin, HasMetadata, PriceMixin
class BaseProductPage(
BasePage,
DescriptionMixin,
PriceMixin,
Returns[Product],
HasMetadata[ProductMetadata],
):
""":class:`BasePage` subclass for :class:`Product`."""
class Processors(BasePage.Processors):
aggregateRating = [rating_processor]
brand = [brand_processor]
breadcrumbs = [breadcrumbs_processor]
description = [description_processor]
descriptionHtml = [description_html_processor]
gtin = [gtin_processor]
price = [price_processor]
regularPrice = [simple_price_processor]
availability = [string_processor]
canonicalUrl = [string_processor]
color = [string_processor]
currency = [string_processor]
currencyRaw = [string_processor]
features = [list_processor(string_processor)]
mpn = [string_processor]
name = [string_processor]
productId = [string_processor]
size = [string_processor]
sku = [string_processor]
style = [string_processor]
url = [string_processor]
class ProductPage(
Page, DescriptionMixin, PriceMixin, Returns[Product], HasMetadata[ProductMetadata]
):
""":class:`Page` subclass for :class:`Product`."""
class Processors(Page.Processors):
aggregateRating = [rating_processor]
brand = [brand_processor]
breadcrumbs = [breadcrumbs_processor]
description = [description_processor]
descriptionHtml = [description_html_processor]
gtin = [gtin_processor]
price = [price_processor]
regularPrice = [simple_price_processor]
availability = [string_processor]
canonicalUrl = [string_processor]
color = [string_processor]
currency = [string_processor]
currencyRaw = [string_processor]
features = [list_processor(string_processor)]
mpn = [string_processor]
name = [string_processor]
productId = [string_processor]
size = [string_processor]
sku = [string_processor]
style = [string_processor]
url = [string_processor]
@attrs.define
class AutoProductPage(BaseProductPage):
product: Product
@auto_field
def additionalProperties(self) -> Optional[List[AdditionalProperty]]:
return self.product.additionalProperties
@auto_field
def aggregateRating(self) -> Optional[AggregateRating]:
return self.product.aggregateRating
@auto_field
def availability(self) -> Optional[str]:
return self.product.availability
@auto_field
def brand(self) -> Optional[Brand]:
return self.product.brand
@auto_field
def breadcrumbs(self) -> Optional[List[Breadcrumb]]:
return self.product.breadcrumbs
@auto_field
def canonicalUrl(self) -> Optional[str]:
return self.product.canonicalUrl
@auto_field
def color(self) -> Optional[str]:
return self.product.color
@auto_field
def currency(self) -> Optional[str]:
return self.product.currency
@auto_field
def currencyRaw(self) -> Optional[str]:
return self.product.currencyRaw
@auto_field
def description(self) -> Optional[str]:
return self.product.description
@auto_field
def descriptionHtml(self) -> Optional[str]:
return self.product.descriptionHtml
@auto_field
def features(self) -> Optional[List[str]]:
return self.product.features
@auto_field
def gtin(self) -> Optional[List[Gtin]]:
return self.product.gtin
@auto_field
def images(self) -> Optional[List[Image]]:
return self.product.images
@auto_field
def mainImage(self) -> Optional[Image]:
return self.product.mainImage
@auto_field
def metadata(self) -> Optional[ProductMetadata]:
return self.product.metadata
@auto_field
def mpn(self) -> Optional[str]:
return self.product.mpn
@auto_field
def name(self) -> Optional[str]:
return self.product.name
@auto_field
def price(self) -> Optional[str]:
return self.product.price
@auto_field
def productId(self) -> Optional[str]:
return self.product.productId
@auto_field
def regularPrice(self) -> Optional[str]:
return self.product.regularPrice
@auto_field
def size(self) -> Optional[str]:
return self.product.size
@auto_field
def sku(self) -> Optional[str]:
return self.product.sku
@auto_field
def style(self) -> Optional[str]:
return self.product.style
@auto_field
def url(self) -> str:
return self.product.url
@auto_field
def variants(self) -> Optional[List[ProductVariant]]:
return self.product.variants