generated from tanikairwin/ci-full-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreatesessions.py
51 lines (40 loc) · 1.9 KB
/
createsessions.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
# create_sessions.py
import os
import django
from datetime import datetime, timedelta
import pytz
from django.utils import timezone
# Setup Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'soul_living.settings')
django.setup()
from yg_bookings.models import Sessions
def create_sessions():
timezone = pytz.timezone('UTC') # Adjust to your timezone if necessary
start_date = datetime.now().date() # Start from today
end_date = start_date + timedelta(days=90) # Create sessions for 3 months
session_times = [
('10:00', 60), # 10 AM, 1 hour
('12:00', 90), # 12 PM, 1.5 hours
('19:00', 60), # 7 PM, 1 hour
]
days_of_week = ['Tuesday', 'Thursday', 'Sunday']
for single_date in (start_date + timedelta(n) for n in range((end_date - start_date).days)):
if single_date.strftime('%A') in days_of_week:
for start_time, duration in session_times:
start_datetime = timezone.localize(datetime.combine(single_date, datetime.strptime(start_time, '%H:%M').time()))
end_datetime = start_datetime + timedelta(minutes=duration)
print(f"Creating session: Start: {start_datetime}, End: {end_datetime}")
title = f"{'Meditation' if start_time == '19:00' else 'Yoga'} {'and Yoga' if start_time == '12:00' else ''}"
try:
Sessions.objects.create(
title=title,
start_time=start_datetime,
date=single_date,
duration=timedelta(minutes=duration),
description=f"{title} session on {single_date.strftime('%A')} at {start_time}",
)
except Exception as e:
print(f"Error creating session: {e}")
print('Successfully created sessions')
if __name__ == '__main__':
create_sessions()