add script for generating fake testing data
This commit is contained in:
1 parent
f8a6ade8e6
commit
3f86cc1b57
6 files changed
+683
-373
No files matched your search
@@ -2,3 +2,6 @@
|
||||
*.venv/
|
||||
*.env
|
||||
*cache*
|
||||
.python-version
|
||||
*.xml
|
||||
.vscode/
|
||||
@@ -5,14 +5,20 @@ from datetime import datetime
|
||||
from typing import Annotated
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from pydantic import BeforeValidator
|
||||
from pydantic import BeforeValidator, PlainSerializer
|
||||
from pydantic_xml import BaseXmlModel, RootXmlModel, element, wrapped
|
||||
|
||||
from fhdhview.core.config import settings
|
||||
|
||||
DT = Annotated[datetime, BeforeValidator(lambda v: datetime.strptime(v, "%Y%m%d%H%M").replace(
|
||||
tzinfo=ZoneInfo(settings.timezone)
|
||||
))]
|
||||
# DateTime annotation with timezone handling and serialization format
|
||||
# Allows both string and datetime inputs, ensuring they have the correct timezone
|
||||
DT = Annotated[datetime, BeforeValidator(
|
||||
lambda v:
|
||||
(datetime.strptime(v, "%Y%m%d%H%M").replace(tzinfo=ZoneInfo(settings.timezone))
|
||||
if isinstance(v, str)
|
||||
else (v.replace(tzinfo=ZoneInfo(settings.timezone)))
|
||||
)), PlainSerializer(lambda dt: dt.strftime("%Y%m%d%H%M"))
|
||||
]
|
||||
|
||||
|
||||
class Session(BaseXmlModel, tag='session'):
|
||||
|
||||
Generated
+593
-368
File diff suppressed because it is too large.
Load diff
+3
-1
@@ -11,7 +11,7 @@ dependencies = [
|
||||
"fastapi (>=0.141.1,<0.142.0)",
|
||||
"pydantic-xml (>=2.21.1,<3.0.0)",
|
||||
"sqlmodel (>=0.0.42,<0.0.43)",
|
||||
"uvicorn (>=0.53.0,<0.54.0)",
|
||||
"uvicorn (>=0.54.0,<0.55.0)",
|
||||
"python-multipart (>=0.0.32,<0.0.33)",
|
||||
"pydantic-settings (>=2.15.0,<3.0.0)",
|
||||
"aiosqlite (>=0.22.1,<0.23.0)"
|
||||
@@ -24,6 +24,8 @@ dev = [
|
||||
"ruff (>=0.16.6,<0.17.0)",
|
||||
"httpx2 (>=2.13.1,<3.0.0)",
|
||||
"pytest-asyncio (>=1.4.0,<2.0.0)",
|
||||
"faker (>=40.44.0,<41.0.0)",
|
||||
"lxml (>=6.1.3,<7.0.0)",
|
||||
]
|
||||
|
||||
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,74 @@
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from random import randint, sample
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from faker import Faker
|
||||
from faker.providers import company
|
||||
|
||||
from fhdhview.services.screenwriter.schema import AAMPos, Session, Sessions
|
||||
|
||||
fake = Faker()
|
||||
fake.add_provider(company)
|
||||
|
||||
zaal = [
|
||||
"DenHaag_zaal_1",
|
||||
"DenHaag_zaal_2",
|
||||
"DenHaag_zaal_3",
|
||||
"DenHaag_zaal_4",
|
||||
"DenHaag_zaal_5",
|
||||
"DenHaag_zaal_6",
|
||||
"Filmhuis Den Haag 10 (buitenbios)"
|
||||
]
|
||||
|
||||
kw_age = [
|
||||
"vanaf 6 jaar",
|
||||
"vanaf 9 jaar",
|
||||
"vanaf 12 jaar",
|
||||
"vanaf 14 jaar",
|
||||
"vanaf 18 jaar",
|
||||
"Alle leeftijden"
|
||||
]
|
||||
|
||||
kw_keywords = [
|
||||
"Angst",
|
||||
"Discriminatie",
|
||||
"Drugs- en/of alcoholmisbruik",
|
||||
"Grof taalgebruik",
|
||||
"Gevaarlijk gedrag",
|
||||
"Geweld",
|
||||
"Seks"
|
||||
]
|
||||
|
||||
attr_extra = [
|
||||
"EN subs"
|
||||
]
|
||||
|
||||
sessions: list[Session] = []
|
||||
|
||||
for i in range(20):
|
||||
start_time = datetime.now(tz=ZoneInfo("Europe/Amsterdam"))+timedelta(minutes=randint(-20, 59))
|
||||
|
||||
attrs = sample(kw_age, 1) + sample(kw_keywords, randint(0, 3)) + sample(attr_extra, randint(0, 1))
|
||||
|
||||
|
||||
session = Session(
|
||||
session_id=randint(1000, 9999),
|
||||
screen_identifier=sample(zaal, 1)[0],
|
||||
complex_identifier="Filmhuis Den Haag",
|
||||
start=start_time,
|
||||
end=start_time+timedelta(hours=2),
|
||||
feature_duration=int(timedelta(hours=2).total_seconds()),
|
||||
title=fake.catch_phrase(),
|
||||
rating=randint(1, 10),
|
||||
seats_available=100,
|
||||
seats_sold=randint(0, 100),
|
||||
attributes=attrs
|
||||
)
|
||||
sessions.append(session)
|
||||
|
||||
xml_data = AAMPos(sessions=Sessions(root=sessions))
|
||||
|
||||
|
||||
with open("test_xml.xml", "wb") as f:
|
||||
result = xml_data.to_xml(pretty_print=True)
|
||||
f.write(result if isinstance(result, bytes) else result.encode("utf-8"))
|
||||
Reference in new issue
Block a user