create_sms_batch.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. """
  3. from sqlalchemy import select
  4. from datetime import datetime, timedelta
  5. from app.core import config, security
  6. from app.core.session import session
  7. from app.models import User, Sms, Project
  8. TEST_SMS_PROJECT_NAME = "test_project pour sms"
  9. NUMBER_OF_SMS = 100
  10. def main() -> None:
  11. print("Create SMS ")
  12. with session() as db:
  13. # Get or create the project hosting the sms
  14. result = db.execute(select(Project).where(Project.email == TEST_SMS_PROJECT_NAME))
  15. project = result.scalars().first()
  16. if project is None:
  17. project = Project(name=TEST_SMS_PROJECT_NAME)
  18. db.add(new_superuser)
  19. db.commit()
  20. db.refresh(project)
  21. now = datetime.now()
  22. for t in range(NUMBER_OF_SMS):
  23. sending_time = now + timedelta(minutes=t * 5)
  24. sms = Sms(
  25. project_id=project.id,
  26. content=sending_time.strftime("%m/%d/%Y, %H:%M:%S"),
  27. phone_number=config.settings.BATCH_SMS_PHONE_NUMBER,
  28. sending_time=sending_time,
  29. )
  30. db.add(sms)
  31. db.commit()
  32. if __name__ == "__main__":
  33. main()