Skip to content

Commit d1a569a

Browse files
DAFT-13: Add a fallback for fetching the ID (TheJokersThief#14)
1 parent 1e52efe commit d1a569a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

daft_scraper/listing.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def post_load(self, data, **kwargs):
105105
data['url'] = self.get_url(data['seoFriendlyPath'])
106106
return data
107107

108-
id = fields.Int()
108+
_id = fields.Int()
109109
title = fields.Str()
110110

111111
seoTitle = fields.Str()
@@ -135,6 +135,8 @@ def post_load(self, data, **kwargs):
135135

136136
class Listing(dict):
137137
_ad_page_info = None
138+
_id = None
139+
url = None
138140

139141
def __init__(self, data: dict):
140142
self.__dict__ = data
@@ -147,6 +149,13 @@ def ad_page_info(self):
147149
self._ad_page_info = json.loads(script_text.string)
148150
return self._ad_page_info
149151

152+
@property
153+
def id(self):
154+
if not self._id:
155+
# If we didn't get the ID on the first pass, query the listing page
156+
self._id = self.ad_page_info['props']['pageProps'].get('listing', {}).get('id', None)
157+
return self._id
158+
150159
@property
151160
def description(self) -> str:
152161
return self.ad_page_info['props']['pageProps'].get('listing', {}).get('description', None)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "daft-scraper"
3-
version = "1.2.4"
3+
version = "1.2.5"
44
description = "A webscraper for Daft.ie"
55
authors = ["Evan Smith <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)