File size: 2,038 Bytes
d2d3ca7
 
 
 
 
 
9135c43
d2d3ca7
9135c43
d2d3ca7
 
 
 
9135c43
d2d3ca7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from peewee import *
from datetime import datetime
from playhouse.sqlite_ext import *

# Initialize database

json_structure = "JSON column with hash with keys 'title': str, official title of the project, 'deposit': int (in percentage), sum of all deposit payments before the apartment is complete. 'min_price': int, lowest available apartment price in CZK with VAT. It should not be booked or sold., 'average_price_per_sqm': int, average price per square meter of the lowest available apartment. 'status': str, status of the project (preparation, selling, sold out), 'city': str, city of the project, 'lat': float, gps coordinates of the project, 'lng': float, gps coordinates of the project, 'start_year': int, year of construction start, 'end_year': int, estimated year of construction end, 'developer': str, name of the contruction company/developer, 'ignore': bool, if True, the project does not have any apartments for sale. Some values can be null/unknown"

db = SqliteExtDatabase('estate.db')

db_description = f"""Table "project" - list of real estate projects (novostavby) in Czech Republic
    url: url of the project.
    structure: {json_structure}.
    content: unstructured additional information about the project.
    created_at: date and time of creation.
"""

class Project(Model):
    url = CharField(unique=True)
    structure = JSONField(null=True)
    content = TextField(null=True)
    created_at = DateTimeField(default=datetime.now)

    class Meta:
        database = db

def init_database():
    """Initialize the database and create tables"""
    print("Initializing database...")
    db.connect()
    db.drop_tables([Project])
    db.create_tables([Project])
    print("Created tables successfully!")
    
    # Add some test data if needed
    test_urls = [
        'https://brnojedna.cz/'
    ]
    
    for url in test_urls:
        Project.get_or_create(url=url)
    
    print(f"Number of projects in database: {Project.select().count()}")
    db.close()

if __name__ == "__main__":
    init_database()