-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove cdn folder to make things more clear (#71)
* 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
Showing
17 changed files
with
71 additions
and
935 deletions.
There are no files selected for viewing
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/eatery_blue_backend/management/commands/populate_models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.