adding last seen date into the listing
This commit is contained in:
parent
4b6b8628c2
commit
29c8d1960b
2 changed files with 22 additions and 4 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
from rec.query import listing_query
|
from rec.query import listing_query
|
||||||
from rec.districts import get_districts
|
from rec.districts import get_districts
|
||||||
import pathlib
|
import pathlib
|
||||||
import json
|
|
||||||
from data_access import Listing
|
from data_access import Listing
|
||||||
|
|
||||||
folder = pathlib.Path("data/rs/")
|
folder = pathlib.Path("data/rs/")
|
||||||
|
|
@ -20,7 +19,7 @@ for district, locid in districts.items():
|
||||||
max_price=1000000,
|
max_price=1000000,
|
||||||
location_id=locid,
|
location_id=locid,
|
||||||
page_size=500,
|
page_size=500,
|
||||||
max_days_since_added=7,
|
max_days_since_added=None,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
@ -35,6 +34,5 @@ for district, locid in districts.items():
|
||||||
identifier = property["identifier"]
|
identifier = property["identifier"]
|
||||||
|
|
||||||
listing = Listing(identifier)
|
listing = Listing(identifier)
|
||||||
with open(listing.path_listing_json(), "w") as f:
|
listing.dump_listing(property)
|
||||||
json.dump(property, f)
|
|
||||||
print() # break line as we used end=, above.
|
print() # break line as we used end=, above.
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,16 @@ class Listing:
|
||||||
self.path_floorplan_folder().mkdir(parents=True, exist_ok=True)
|
self.path_floorplan_folder().mkdir(parents=True, exist_ok=True)
|
||||||
return self.path_floorplan_folder() / f"{order}_{name}"
|
return self.path_floorplan_folder() / f"{order}_{name}"
|
||||||
|
|
||||||
|
def path_last_seen_listing(self) -> pathlib.Path:
|
||||||
|
return self.path_listing() / "last_seen.json"
|
||||||
|
|
||||||
|
def dump_listing(self, d: dict):
|
||||||
|
with open(self.path_listing_json(), "w") as f:
|
||||||
|
json.dump(d, f)
|
||||||
|
with open(self.path_last_seen_listing(), "w") as f:
|
||||||
|
dt = datetime.datetime.now().isoformat()
|
||||||
|
json.dump(dt, f)
|
||||||
|
|
||||||
def list_floorplans(self):
|
def list_floorplans(self):
|
||||||
images = list(self.path_floorplan_folder().glob("*"))
|
images = list(self.path_floorplan_folder().glob("*"))
|
||||||
# todo add check if return is image
|
# todo add check if return is image
|
||||||
|
|
@ -203,6 +213,15 @@ class Listing:
|
||||||
ds = datetime.datetime.fromtimestamp(ts)
|
ds = datetime.datetime.fromtimestamp(ts)
|
||||||
return (now - ds).days
|
return (now - ds).days
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_seen(self) -> datetime.datetime:
|
||||||
|
if not self.path_last_seen_listing().exists():
|
||||||
|
return None
|
||||||
|
|
||||||
|
with open(self.path_last_seen_listing(), 'r') as f:
|
||||||
|
datetime_str = json.load(f)
|
||||||
|
return datetime.fromisoformat(datetime_str)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serviceCharge(self) -> float:
|
def serviceCharge(self) -> float:
|
||||||
ds = self.detailobject["property"].get("tenureInfo", {}).get("content", [])
|
ds = self.detailobject["property"].get("tenureInfo", {}).get("content", [])
|
||||||
|
|
@ -255,6 +274,7 @@ class Listing:
|
||||||
"tenure_type": self.tenure_type,
|
"tenure_type": self.tenure_type,
|
||||||
"updated_days": self.updateDaysAgo,
|
"updated_days": self.updateDaysAgo,
|
||||||
"status": self.status,
|
"status": self.status,
|
||||||
|
"last_seen": self.last_seen,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue