-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.py
More file actions
119 lines (108 loc) · 3.89 KB
/
initialize.py
File metadata and controls
119 lines (108 loc) · 3.89 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'webapp.settings'
from django.contrib.auth.models import User
from vendor.models import *
from urllib import urlopen
import json
"""
def dumpclean(obj):
if type(obj) == dict:
for k, v in obj.items():
if hasattr(v, '__iter__'):
print k
dumpclean(v)
else:
print '%s : %s' % (k, v)
elif type(obj) == list:
for v in obj:
if hasattr(v, '__iter__'):
dumpclean(v)
else:
print v
else:
print obj
"""
url = urlopen("http://test-diningdata.itg.gatech.edu:80/api/DiningLocations").read()
info = json.loads(url)
#dumpclean(result)""
for rest in info:
user = rest["Name"].replace("(","")
user = user.replace(")","")
password = rest["Name"].split(' ')[0]
tags = ""
for tag in rest["Tags"]:
tags = tags + "#" + tag["Name"]
#Default username is name of restaurant without brackets and password is first word of Restaurant
User.objects.create_user( user , password+'@gatech.edu', password)
#Default Logo and Menu is the starbucks one for now
description = rest["Description"]
if description == None:
description = ""
resid = ResID(name=rest["Name"], description=description, logo='logo/starbuckslogo.png', menu='menu/starbucksmenu.jpg', tags=tags)
resid.save()
open_time_m = '8:00'
close_time_m = '20:00'
open_time_t = '8:00'
close_time_t = '20:00'
open_time_w = '8:00'
close_time_w = '20:00'
open_time_r = '8:00'
close_time_r = '20:00'
open_time_f = '8:00'
close_time_f = '20:00'
open_time_s = '8:00'
close_time_s = '20:00'
open_time_h = '8:00'
close_time_h = '20:00'
m = False
t = False
w = False
r = False
f = False
s = False
h = False
for dictHours in rest["HoursOfOperations"]:
if dictHours["Close"]["Day"]==1:
open_time_m = dictHours["Open"]["Time"]
close_time_m = dictHours["Close"]["Time"]
m = True
elif dictHours["Close"]["Day"]==2:
open_time_t = dictHours["Open"]["Time"]
close_time_t = dictHours["Close"]["Time"]
t = True
elif dictHours["Close"]["Day"]==3:
open_time_w = dictHours["Open"]["Time"]
close_time_w = dictHours["Close"]["Time"]
w = True
elif dictHours["Close"]["Day"]==4:
open_time_r = dictHours["Open"]["Time"]
close_time_r = dictHours["Close"]["Time"]
r = True
elif dictHours["Close"]["Day"]==5:
open_time_f = dictHours["Open"]["Time"]
close_time_f = dictHours["Close"]["Time"]
f = True
elif dictHours["Close"]["Day"]==6:
open_time_s = dictHours["Open"]["Time"]
close_time_s = dictHours["Close"]["Time"]
s = True
elif dictHours["Close"]["Day"]==7:
open_time_h = dictHours["Open"]["Time"]
close_time_h = dictHours["Close"]["Time"]
h = True
hours = Hours(open_time_m=open_time_m, close_time_m=close_time_m,
open_time_t=open_time_t, close_time_t=close_time_t,
open_time_w=open_time_w, close_time_w=close_time_w,
open_time_r=open_time_r, close_time_r=close_time_r,
open_time_f=open_time_f, close_time_f=close_time_f,
open_time_s=open_time_s, close_time_s=close_time_s,
open_time_h=open_time_h, close_time_h=close_time_h,
m=m, t=t, w=w, r=r, f=f, s=s, h=h)
hours.save()
details = rest["LocationDetails"]
if details == None:
details = ""
loc = Location(address="", details=details, latitude=rest["Latitude"], longitude=rest["Longitude"])
loc.save()
usermap = UserMap(username=user, resid=resid, hours=hours, loc=loc)
usermap.save()