-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_gsrs.py
More file actions
40 lines (33 loc) · 1.45 KB
/
load_gsrs.py
File metadata and controls
40 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import csv
from django.core.management.base import BaseCommand
from gsr_booking.models import GSR, clear_gsr_location_caches
class Command(BaseCommand):
def handle(self, *args, **kwargs):
with open("gsr_booking/data/gsr_data.csv") as data:
reader = csv.reader(data)
next(reader)
for lid, gid, name, service, bookable_days in reader:
# gets image from s3 given the lid and gid
# TODO: fix image url!
image_url = (
f"https://s3.us-east-2.amazonaws.com/labs.api/gsr/lid-{lid}-gid-{gid}.jpg"
)
kind = (
GSR.KIND_PENNGROUPS
if service == "penngroups"
else GSR.KIND_WHARTON if service == "wharton" else GSR.KIND_LIBCAL
)
GSR.objects.update_or_create(
lid=lid,
gid=gid,
defaults={
"name": name,
"kind": kind,
"image_url": image_url,
"bookable_days": int(bookable_days),
},
)
# Note: Caches are automatically cleared by post_save signals on GSR model
# But we clear explicitly here as well for clarity and to handle edge cases
clear_gsr_location_caches()
self.stdout.write("Uploaded GSRs and cleared location caches!")