-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.py
49 lines (39 loc) · 1.28 KB
/
preload.py
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
from aredis_om import NotFoundError
import app.api.analytics.dao as AnalyticsDao
from app.api.analytics.models import Analytics
from app.api.shortie.dao import find_by_short_url_id_or_alias
from app.api.shortie.models import ShortenedURL
from app.api.users.dao import find_by_username
from app.api.users.models import User
async def load_users() -> None:
try:
await find_by_username("tortellini")
except NotFoundError:
user = User(
username="tortellini",
password="85b7ad22cd1825e5001d8bae3b2c89e2bd1647344298181fc9d62e46e60f51dc",
)
await user.save()
async def load_url() -> None:
try:
await find_by_short_url_id_or_alias("test")
except NotFoundError:
url = ShortenedURL(
short_url_id="test",
alias="testing",
short_url=f"https://shortie/test",
long_url="google.com",
owner="tortellini",
)
await url.save()
async def load_analytics() -> None:
try:
await AnalyticsDao.find_by_short_url_id_or_alias("test")
except NotFoundError:
analytics = Analytics(
short_url_id="test",
alias="testing",
clicks=0,
owner="tortellini",
)
await analytics.save()