Spaces:
Sleeping
Sleeping
File size: 1,878 Bytes
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 48 49 50 51 |
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, initial deposit (in percentage), 'min_price': int, lowest available property price with VAT. It should not be booked or sold., '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. Some values can be null/unknown"
db = SqliteExtDatabase('estate.db', pragmas=(
('cache_size', -1024 * 64), # 64MB page-cache.
('journal_mode', 'wal'), # Use WAL-mode (you should always use this!).
('foreign_keys', 1))) # Enforce foreign-key constraints.
# Define the Project model
db_description = f"""Table "project" - list of real estate projects (novostavby) in Czech Republic
url: url of the project.
structure: {json_structure}.
content: contents of the website.
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() |