update food model and required commands
This commit is contained in:
parent
ff2a554f12
commit
7d9ad7601b
13
ofu_app/apps/food/management/commands/delete_food.py
Normal file
13
ofu_app/apps/food/management/commands/delete_food.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from apps.food.models import Menu, HappyHour, SingleFood
|
||||||
|
from apps.food.utils import migrate_data
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Imports Food from special Websites"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
migrate_data.delete()
|
||||||
@ -39,22 +39,42 @@ def writeStudentenwerkDataInDB(data):
|
|||||||
|
|
||||||
|
|
||||||
def writeFekideDataInDB(data):
|
def writeFekideDataInDB(data):
|
||||||
|
print(data)
|
||||||
for happyhour_data in data['happyhours']:
|
for happyhour_data in data['happyhours']:
|
||||||
time = str(happyhour_data['time']).replace(" ", "").split("-")
|
time = str(happyhour_data['time']).replace(" ", "").split("-")
|
||||||
happyhour, new = HappyHour.objects.get_or_create(date=datetime.strptime(data['day'], "%A, %d.%m.%Y"),
|
happyhour, new = HappyHour.objects.get_or_create(date=datetime.strptime(data['day'], "%A, %d.%m.%Y"),
|
||||||
location=happyhour_data['location'],
|
location=happyhour_data['location'],
|
||||||
description=happyhour_data['description'],
|
description=happyhour_data['description'],
|
||||||
starttime=datetime.strptime(time[0], "%H:%M"),
|
starttime=datetime.strptime(time[0], "%H:%M").time(),
|
||||||
endtime=datetime.strptime(time[1], "%H:%M"))
|
endtime=datetime.strptime(time[1], "%H:%M").time())
|
||||||
|
print("HH: %s, NEW: %s" % (str(happyhour), str(new)))
|
||||||
if not new:
|
if not new:
|
||||||
|
print("Update db object " + happyhour.location)
|
||||||
happyhour.date = datetime.strptime(data['day'], "%A, %d.%m.%Y")
|
happyhour.date = datetime.strptime(data['day'], "%A, %d.%m.%Y")
|
||||||
happyhour.location = happyhour_data['location']
|
happyhour.location = happyhour_data['location']
|
||||||
happyhour.description = happyhour_data['description']
|
happyhour.description = happyhour_data['description']
|
||||||
happyhour.starttime = datetime.strptime(time[0], "%H:%M")
|
happyhour.starttime = datetime.strptime(time[0], "%H:%M").time()
|
||||||
happyhour.endtime = datetime.strptime(time[1], "%H:%M")
|
happyhour.endtime = datetime.strptime(time[1], "%H:%M").time()
|
||||||
|
happyhour.save()
|
||||||
|
|
||||||
|
|
||||||
|
def writeoutDBObjects():
|
||||||
|
pprint("SingleFood: " + str(SingleFood.objects.count()))
|
||||||
|
pprint("Menu: " + str(Menu.objects.count()))
|
||||||
|
pprint("HappyHour: " + str(HappyHour.objects.count()))
|
||||||
|
|
||||||
|
|
||||||
|
def delete():
|
||||||
|
happy_hours = HappyHour.objects.all()
|
||||||
|
print("Deleted following Happy Hours:")
|
||||||
|
for happy_hour in happy_hours:
|
||||||
|
print("Happy Hour: Location: %s, Description: %s" % (str(happy_hour.location), str(happy_hour.description)))
|
||||||
|
happy_hour.delete()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
print("Aktueller Stand:")
|
||||||
|
writeoutDBObjects()
|
||||||
# get food jsons
|
# get food jsons
|
||||||
writeStudentenwerkDataInDB(mensa_page_parser.parsePage(LINK_AUSTR_MENSA))
|
writeStudentenwerkDataInDB(mensa_page_parser.parsePage(LINK_AUSTR_MENSA))
|
||||||
writeStudentenwerkDataInDB(mensa_page_parser.parsePage(LINK_FEKI_MENSA))
|
writeStudentenwerkDataInDB(mensa_page_parser.parsePage(LINK_FEKI_MENSA))
|
||||||
@ -62,9 +82,8 @@ def main():
|
|||||||
writeStudentenwerkDataInDB(cafete_page_parser.parsePage(LINK_MARKUS_CAFETE))
|
writeStudentenwerkDataInDB(cafete_page_parser.parsePage(LINK_MARKUS_CAFETE))
|
||||||
writeFekideDataInDB(fekide_happyhour_page_parser.parsePage(LINK_FEKIDE_GUIDE))
|
writeFekideDataInDB(fekide_happyhour_page_parser.parsePage(LINK_FEKIDE_GUIDE))
|
||||||
|
|
||||||
pprint("SingleFood: " + str(SingleFood.objects.count()))
|
print("Neuer Stand:")
|
||||||
pprint("Menu: " + str(Menu.objects.count()))
|
writeoutDBObjects()
|
||||||
pprint("HappyHour: " + str(HappyHour.objects.count()))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user