mirror of
https://github.com/Findus23/acronomy.git
synced 2024-09-19 15:33:45 +02:00
29 lines
1 KiB
Python
29 lines
1 KiB
Python
from datetime import date, timedelta
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from acros.models import Acronym, AcroOfTheDay
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Selects Acronym of the Day for the next day'
|
|
|
|
def add_arguments(self, parser):
|
|
# Named (optional) arguments
|
|
parser.add_argument(
|
|
'--today',
|
|
action='store_true',
|
|
help='replace todays acronyms of the day instead of tomorrows',
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
today = date.today()
|
|
tomorrow = today + timedelta(days=1)
|
|
AcroOfTheDay.objects.filter(date__gt=today).delete()
|
|
if options["today"]:
|
|
AcroOfTheDay.objects.filter(date=today).delete()
|
|
AcroOfTheDay.objects.filter(date__lt=today).delete()
|
|
selected = Acronym.objects.order_by('?')[:5]
|
|
for i, acr in enumerate(selected):
|
|
AcroOfTheDay.objects.create(acronym=acr, date=today if options["today"] else tomorrow, order=i)
|
|
print(acr.name)
|