parameterize data path when fetching listings

This commit is contained in:
Viktor Barzin 2025-05-14 20:19:08 +00:00
parent ea56555884
commit 48d379567b
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
3 changed files with 28 additions and 11 deletions

View file

@ -6,17 +6,15 @@ from rec import floorplan, routing
import re
import datetime
_DATA_DIR = pathlib.Path("data/rs/")
@dataclass()
class Listing:
identifier: int
_cached: Dict = None
data_dir: pathlib.Path = pathlib.Path("data/rs/")
@staticmethod
def get_all_listings() -> List["Listing"]:
listing_paths = sorted(list(_DATA_DIR.glob("*/listing.json")))
def get_all_listings(self) -> List["Listing"]:
listing_paths = sorted(list(self.data_dir.glob("*/listing.json")))
identifiers = []
for listing_path in listing_paths:
with open(listing_path) as f:
@ -26,7 +24,7 @@ class Listing:
return identifiers
def path_listing(self) -> pathlib.Path:
p = _DATA_DIR / str(self.identifier)
p = self.data_dir / str(self.identifier)
p.mkdir(parents=True, exist_ok=True)
return p