forked from rc/aircox
start working on schedule command/view
This commit is contained in:
@ -4,13 +4,12 @@ from django.core.management.base import BaseCommand, CommandError
|
||||
import programs.models as models
|
||||
import programs.settings
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
class Command (BaseCommand):
|
||||
help= "Take a look at the programs directory to check on new podcasts"
|
||||
|
||||
|
||||
|
||||
|
||||
def handle(self, *args, **options):
|
||||
def handle (self, *args, **options):
|
||||
programs = models.Program.objects.filter(schedule__isnull = True)
|
||||
|
||||
for program in programs:
|
||||
@ -24,6 +23,10 @@ class Command(BaseCommand):
|
||||
for filename in os.listdir(path):
|
||||
long_filename = path + '/' + filename
|
||||
|
||||
# check for new sound files
|
||||
# stat the sound files
|
||||
# match sound files against episodes - if not found, create it
|
||||
# upload public podcasts to mixcloud if required
|
||||
except:
|
||||
pass
|
||||
|
||||
|
72
programs/management/commands/schedule.py
Normal file
72
programs/management/commands/schedule.py
Normal file
@ -0,0 +1,72 @@
|
||||
import datetime
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils import timezone, dateformat
|
||||
|
||||
import programs.models as models
|
||||
import programs.settings
|
||||
|
||||
|
||||
class Diffusion:
|
||||
ref = None
|
||||
date_start = None
|
||||
date_end = None
|
||||
|
||||
def __init__ (self, ref, date_start, date_end):
|
||||
self.ref = ref
|
||||
self.date_start = date_start
|
||||
self.date_end = date_end
|
||||
|
||||
def __lt__ (self, d):
|
||||
return self.date_start < d.date_start and \
|
||||
self.date_end < d.date_end
|
||||
|
||||
|
||||
|
||||
class Command (BaseCommand):
|
||||
help= "check sounds to diffuse"
|
||||
|
||||
diffusions = set()
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.get_next_events()
|
||||
self.get_next_episodes()
|
||||
|
||||
for diffusion in self.diffusions:
|
||||
print( diffusion.ref.__str__()
|
||||
, diffusion.date_start
|
||||
, diffusion.date_end)
|
||||
|
||||
|
||||
|
||||
def get_next_episodes (self):
|
||||
schedules = models.Schedule.objects.filter()
|
||||
for schedule in schedules:
|
||||
date = schedule.next_date()
|
||||
if not date:
|
||||
continue
|
||||
|
||||
dt = datetime.timedelta( hours = schedule.duration.hour
|
||||
, minutes = schedule.duration.minute
|
||||
, seconds = schedule.duration.second )
|
||||
|
||||
ref = models.Episode.objects.filter(date = date)[:1]
|
||||
if not ref:
|
||||
ref = ( schedule.parent, )
|
||||
|
||||
diffusion = Diffusion(ref[0], date, date + dt)
|
||||
self.diffusions.add(diffusion)
|
||||
|
||||
|
||||
def get_next_events (self):
|
||||
events = models.Event.objects.filter(date_end__gt = timezone.now(),
|
||||
canceled = False) \
|
||||
.extra(order_by = ['date'])[:10]
|
||||
for event in events:
|
||||
diffusion = Diffusion(event, event.date, event.date_end)
|
||||
self.diffusions.add(diffusion)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user