add models
This commit is contained in:
parent
bc5c258170
commit
f7fb891648
2 changed files with 52 additions and 8 deletions
|
|
@ -1,5 +1,54 @@
|
||||||
from sqlmodel import SQLModel, Field
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime
|
||||||
|
import enum
|
||||||
|
from typing import Any, Dict, List
|
||||||
|
from sqlmodel import JSON, Column, Enum, SQLModel, Field
|
||||||
|
|
||||||
|
|
||||||
class Listing(SQLModel, table=True):
|
@dataclass
|
||||||
|
class PriceHistoryItem:
|
||||||
|
first_seen: datetime
|
||||||
|
last_seen: datetime
|
||||||
|
price: float
|
||||||
|
|
||||||
|
|
||||||
|
class ListingSite(enum.StrEnum):
|
||||||
|
RIGHTMOVE = "rightmove"
|
||||||
|
# ZOOPLA = "zoopla"
|
||||||
|
# ... add more
|
||||||
|
|
||||||
|
|
||||||
|
class Listing(SQLModel, table=False):
|
||||||
id: int = Field(primary_key=True)
|
id: int = Field(primary_key=True)
|
||||||
|
price: float = Field(nullable=False)
|
||||||
|
number_of_bedrooms: int = Field(nullable=False)
|
||||||
|
square_meters: float | None = Field(default=None, nullable=True)
|
||||||
|
agency: str | None = Field(default=None, nullable=True)
|
||||||
|
council_tax_band: str | None = Field(default=None, nullable=True)
|
||||||
|
longtitude: float = Field(nullable=False)
|
||||||
|
latitude: float = Field(nullable=False)
|
||||||
|
price_history: List[Dict[str, Any]] = Field(default_factory=list, sa_type=JSON)
|
||||||
|
listing_site: ListingSite = Field(nullable=False)
|
||||||
|
last_seen: datetime = Field(default_factory=datetime.now, nullable=False)
|
||||||
|
photo_thumbnail: str | None = Field(default=None, nullable=True)
|
||||||
|
|
||||||
|
|
||||||
|
class FurnishType(enum.StrEnum):
|
||||||
|
FURNISHED = "furnished"
|
||||||
|
UNFURNISHED = "unfurnished"
|
||||||
|
PART_FURNISHED = "partFurnished"
|
||||||
|
|
||||||
|
|
||||||
|
class RentListing(Listing, table=True):
|
||||||
|
available_from: datetime | None = Field(default=None, nullable=True)
|
||||||
|
furnish_type: FurnishType | None = Field(nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class BuyListing(Listing, table=True):
|
||||||
|
service_charge: float | None = Field(default=None, nullable=True)
|
||||||
|
council_tax_band: str | None = Field(
|
||||||
|
default=None, nullable=True
|
||||||
|
) # e.g., A, B, C, D, E, F, G
|
||||||
|
lease_left: int | None = Field(
|
||||||
|
default=None, nullable=True
|
||||||
|
) # in years, e.g., 90, 80, etc.
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from data_access import Listing
|
from data_access import Listing
|
||||||
|
from models.listing import FurnishType
|
||||||
|
|
||||||
|
|
||||||
class ListingType(enum.StrEnum):
|
class ListingType(enum.StrEnum):
|
||||||
|
|
@ -13,12 +14,6 @@ class ListingType(enum.StrEnum):
|
||||||
RENT = "RENT"
|
RENT = "RENT"
|
||||||
|
|
||||||
|
|
||||||
class FurnishType(enum.StrEnum):
|
|
||||||
FURNISHED = "furnished"
|
|
||||||
UNFURNISHED = "unfurnished"
|
|
||||||
PART_FURNISHED = "partFurnished"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class QueryParameters:
|
class QueryParameters:
|
||||||
listing_type: ListingType
|
listing_type: ListingType
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue