Skip to content

Commit

Permalink
Remove cdn folder to make things more clear (#71)
Browse files Browse the repository at this point in the history
* remove cdn folder to make things more clear

* fix reports getting deleted

* Resolve empty menus issue for cafes

* revert is_cafe breaking change (#72)

* implement adding times for external eateries (#70)

* add necessary files (#73)

* remove unnecessary files

---------

Co-authored-by: Thomas Vignos <tjv37@cornell.edu>
  • Loading branch information
mateow99 and Thomas Vignos authored Nov 15, 2023
1 parent c0c767c commit ad63fe3
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 935 deletions.
Empty file removed src/cdn_parser/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions src/cdn_parser/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions src/cdn_parser/apps.py

This file was deleted.

Empty file.
69 changes: 0 additions & 69 deletions src/cdn_parser/controllers/populate_models.py

This file was deleted.

Empty file.
Empty file.
13 changes: 0 additions & 13 deletions src/cdn_parser/management/commands/populate_models.py

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions src/cdn_parser/tests.py

This file was deleted.

3 changes: 0 additions & 3 deletions src/cdn_parser/views.py

This file was deleted.

6 changes: 0 additions & 6 deletions src/eatery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@ class CampusArea(models.TextChoices):
payment_accepts_meal_swipes = models.BooleanField(null=True, blank=True)
payment_accepts_brbs = models.BooleanField(null=True, blank=True)
payment_accepts_cash = models.BooleanField(null=True, blank=True)


@classmethod
def truncate(cls):
with connection.cursor() as cursor:
cursor.execute('TRUNCATE TABLE {} CASCADE'.format(cls._meta.db_table))
69 changes: 69 additions & 0 deletions src/eatery_blue_backend/management/commands/populate_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from django.core.management.base import BaseCommand
from datetime import datetime
import requests
from eatery.util.constants import CORNELL_DINING_URL
from event.models import Event
from eatery.controllers.populate_eatery import PopulateEateryController
from event.controllers.populate_event import PopulateEventController
from item.controllers.populate_item import PopulateItemController
from category.controllers.populate_category import PopulateCategoryController

class Command(BaseCommand):
help = 'Populates all models'
def handle(self, *args, **kwargs):
self.stdout.write(f"Populating models at {datetime.now()} UTC")
start = int(datetime.now().timestamp())
self.process()
self.stdout.write(f"Populated models ({int(datetime.now().timestamp()) - start}s)")

def get_json(self):
try:
response = requests.get(CORNELL_DINING_URL)
except Exception as e:
raise e
if response.status_code <= 400:
response = response.json()
json_eateries = response["data"]["eateries"]
return json_eateries

def process(self):
"""
1. Get JSON from API
2. create eateries (fron CDN json)
3. create events (from CDN json)
return events_dict = { eatery_id : [event, event, event...], eatery_id : ... }
4. create menus for every eatery's events
return menus_dict = { eatery_id : [menu, menu, menu...] }
5. create categories in each menu
return categories_dict =
{ eatery_id :
{ menu[i] : {"category_name" : id, "category_name" : id...},
menu[i] : {"category_name" : id...}
}
}
6. create items for each category
"""

json_eateries = self.get_json()

Event.truncate()

print("Populating eateries")
PopulateEateryController().process(json_eateries)

print("Populating events")
events_dict = PopulateEventController().process(json_eateries)

print("Populating categories")
categories_dict = PopulateCategoryController().process(events_dict, json_eateries)

print("Populating items")
PopulateItemController().process(categories_dict, json_eateries)

print("Done populating")
4 changes: 2 additions & 2 deletions src/eatery_blue_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework.authtoken",
"rest_framework",
"eatery_blue_backend",
"eatery",
"alert",
"event",
"report",
"item",
"category",
"cdn_parser",
"rest_framework",
"person",
]

Expand Down
1 change: 0 additions & 1 deletion src/eatery_blue_backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@
path("report/", include("report.urls")),
path("alert/", include("alert.urls")),
path("person/", include("person.urls")),
#path("wait_time/", include("wait_time.urls"))
]
1 change: 0 additions & 1 deletion static_sources/cornell_dining_now_eateries.json

This file was deleted.

Loading

0 comments on commit ad63fe3

Please sign in to comment.