Skip to content

Commit

Permalink
only return room if not 404
Browse files Browse the repository at this point in the history
  • Loading branch information
ezwang committed Aug 24, 2019
1 parent a4673cc commit 267aba9
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions penn/studyspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,33 @@ def get_rooms(self, lid, start=None, end=None):
items = category["items"]
items = ",".join([str(x) for x in items])
resp = self._request("GET", "/1.1/space/item/{}?{}".format(items, range_str))
for room in resp.json():
if room["id"] in ROOM_BLACKLIST:
continue
# prepend protocol to urls
if "image" in room and room["image"]:
if not room["image"].startswith("http"):
room["image"] = "https:" + room["image"]
# convert html descriptions to text
if "description" in room:
description = room["description"].replace(u'\xa0', u' ')
room["description"] = BeautifulSoup(description, "html.parser").text.strip()
# remove extra fields
if "formid" in room:
del room["formid"]
# enforce date filter
# API returns dates outside of the range, fix this manually
if start_datetime:
out_times = []
for time in room["availability"]:
parsed_start = datetime.datetime.strptime(time["from"][:-6], "%Y-%m-%dT%H:%M:%S")
if parsed_start >= start_datetime:
out_times.append(time)
room["availability"] = out_times
cat_out["rooms"].append(room)
if cat_out["rooms"]:
output["categories"].append(cat_out)
if resp.ok:
for room in resp.json():
if room["id"] in ROOM_BLACKLIST:
continue
# prepend protocol to urls
if "image" in room and room["image"]:
if not room["image"].startswith("http"):
room["image"] = "https:" + room["image"]
# convert html descriptions to text
if "description" in room:
description = room["description"].replace(u'\xa0', u' ')
room["description"] = BeautifulSoup(description, "html.parser").text.strip()
# remove extra fields
if "formid" in room:
del room["formid"]
# enforce date filter
# API returns dates outside of the range, fix this manually
if start_datetime:
out_times = []
for time in room["availability"]:
parsed_start = datetime.datetime.strptime(time["from"][:-6], "%Y-%m-%dT%H:%M:%S")
if parsed_start >= start_datetime:
out_times.append(time)
room["availability"] = out_times
cat_out["rooms"].append(room)
if cat_out["rooms"]:
output["categories"].append(cat_out)
return output

def book_room(self, item, start, end, fname, lname, email, nickname, custom={}, test=False):
Expand Down

0 comments on commit 267aba9

Please sign in to comment.