-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlisting.py
More file actions
34 lines (28 loc) · 895 Bytes
/
listing.py
File metadata and controls
34 lines (28 loc) · 895 Bytes
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
import re
class Listing():
NON_NUMERIC = re.compile("[^0-9]")
"""Strip non numeric characters from price"""
def __init__(self):
self.post_id = ''
self.make = ''
self.model = ''
self.series = ''
self.price = ''
@classmethod
def create(cls, post_id, make, model, series, price):
"""Factory for class. Assumes parameters are list of size 0 or 1."""
ret = cls()
if post_id:
ret.post_id = post_id[0]
if make:
ret.make = make[0]
if model:
ret.model = model[0]
if series:
ret.series = series[0]
if price:
ret.price = re.sub(Listing.NON_NUMERIC, '', price[0])
return ret
def __str__(self):
return "{0},{1},{2},{3},{4}".format(
self.post_id, self.make, self.model, self.series, self.price)