-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
100 lines (80 loc) · 2.68 KB
/
models.py
File metadata and controls
100 lines (80 loc) · 2.68 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Data models for Morizon.pl scraper."""
import csv
from dataclasses import dataclass, fields
from typing import Optional
@dataclass
class Property:
"""Property listing data model."""
# Basic info
url: str = ""
title: str = ""
listing_id: str = ""
# Price info
price: Optional[str] = None
price_currency: str = "zł"
price_per_sqm: Optional[str] = None
deposit: Optional[str] = None
# Property details
living_area: Optional[str] = None
rooms: Optional[str] = None
floor: Optional[str] = None
total_floors: Optional[str] = None
interior_height: Optional[str] = None
# Property characteristics
condition: Optional[str] = None
market_type: Optional[str] = None
ownership: Optional[str] = None
available_from: Optional[str] = None
contract_type: Optional[str] = None
# Kitchen and bathroom
kitchen_type: Optional[str] = None
bathroom_with_wc: Optional[str] = None
balcony: Optional[str] = None
windows: Optional[str] = None
# Building info
building_type: Optional[str] = None
year_built: Optional[str] = None
heating: Optional[str] = None
# Location
address: Optional[str] = None
street: Optional[str] = None
district: Optional[str] = None
city: Optional[str] = None
voivodeship: Optional[str] = None
# Equipment and amenities
equipment: Optional[str] = None
amenities: Optional[str] = None
media: Optional[str] = None
# Listing info
date_added: Optional[str] = None
date_updated: Optional[str] = None
views: Optional[str] = None
# Agent info
advertiser_type: Optional[str] = None
advertiser_name: Optional[str] = None
agent_company: Optional[str] = None
# Description
description: Optional[str] = None
def export_to_csv(properties: list[Property], filepath: str) -> None:
"""Export properties to CSV file.
Args:
properties: List of Property objects
filepath: Output CSV file path
"""
if not properties:
return
field_names = [f.name for f in fields(Property)]
with open(filepath, "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=field_names)
writer.writeheader()
for prop in properties:
row = {}
for field_name in field_names:
value = getattr(prop, field_name)
# Clean up values for CSV
if value is not None:
if isinstance(value, str):
# Remove newlines and extra whitespace
value = " ".join(value.split())
row[field_name] = value
writer.writerow(row)