-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.py
61 lines (46 loc) · 1.29 KB
/
seed.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
50
51
52
53
54
55
56
57
58
59
60
61
import os
# from datetime import datetime, timedelta
# import main
from src.models import db, Task, Phone
from src.constants import TaskStatus
TEST_PHONE = os.getenv("TEST_PHONE") or "whatsapp:+55555555555"
def create_phones():
phone1 = Phone(number=TEST_PHONE, disabled=False)
phone2 = Phone(number="whatsapp:+66666666555", disabled=False)
phones = [phone1, phone2]
for phone in phones:
db.session.add(phone)
db.session.commit()
print(phones)
return phones
def create_tasks(phones):
# d1 = datetime.now() + timedelta(minutes=10)
# d2 = datetime.now() + timedelta(hours=1)
task1 = Task(
phone=phones[0],
status=TaskStatus.PENDING,
text="First text",
interval=3,
time_unit="MINUTES",
)
task2 = Task(
phone=phones[0],
status=TaskStatus.REPEAT,
text="Second text",
interval=2,
time_unit="HOURS",
)
# task3 = Task(phone=phones[1], status=TaskStatus.PENDING, text="Some text")
tasks = [task1, task2]
for task in tasks:
db.session.add(task)
db.session.commit()
print(tasks)
return tasks
def seed_all():
db.drop_all()
db.create_all()
phones = create_phones()
_ = create_tasks(phones)
if __name__ == "__main__":
seed_all()