-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapters.py
49 lines (35 loc) · 1.24 KB
/
adapters.py
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
import arrow, ujson
class HoursFilter:
def __init__(self, listings, hours_ago=None):
self.listings = listings
self.hours_ago = -1 if not hours_ago else hours_ago * -1
@property
def results(self):
threshold = arrow.utcnow().shift(hours=self.hours_ago)
filtered_listings = list(
filter(lambda l: l.last_update >= threshold, self.listings)
)
return filtered_listings
class ResponseEnvelope:
def __init__(self, api_response):
self.json_obj = ujson.loads(api_response.content)
@property
def listings(self):
return [Listing(l) for l in self.json_obj["value"]]
@property
def next_page_url(self):
return self.json_obj.get("@odata.nextLink", None)
class Listing:
def __init__(self, primative_listing_object):
self.listing_obj = primative_listing_object
@property
def listing_key(self):
return self.listing_obj["ListingKey"]
@property
def last_update(self):
# todo, confirm this
return arrow.get(self.listing_obj["ModificationTimestamp"])
@property
def media(self):
incoming = self.listing_obj["Media"]
return list(filter(lambda m: m["MediaCategory"] == "Photo", incoming))