Skip to content

Commit

Permalink
combine hours for similar rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
ezwang committed Oct 24, 2018
1 parent 195c8c4 commit e6dbcc0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions penn/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ def get_schedule(self):
})
resp.raise_for_status()
raw_data = resp.json()
data = []
data = {}
for item in raw_data["events"]:
name = re.sub(r"\s*(Hours)?\s*-?\s*(CLOSED|OPEN)?$", "", item["title"], re.I).rsplit("-", 1)[0].strip().title()
out = {
"name": re.sub(r"\s*(Hours)?\s*-?\s*(CLOSED|OPEN)$", "", item["title"], re.I),
"all_day": item["all_day"]
}
if not item["all_day"]:
out["start"] = item["start_dt"]
out["end"] = item["end_dt"]
else:
out["day"] = item["start_dt"].split("T")[0]
data.append(out)
return data
if name not in data:
data[name] = {
"name": name,
"hours": []
}
data[name]["hours"].append(out)
return list(data.values())

def get_usage(self):
"""Get fitness locations and their current usage."""
Expand All @@ -53,8 +58,9 @@ def get_usage(self):
for item in soup.findAll("div", {"class": "barChart"}):
data = [x.strip() for x in item.get_text("\n").strip().split("\n")]
data = [x for x in data if x]
name = re.sub(r"\s*(Hours)?\s*-?\s*(CLOSED|OPEN)?$", "", data[0], re.I).strip().title()
output.append({
"name": re.sub(r"\s*(Hours)?\s*-?\s*(CLOSED|OPEN)$", "", data[0], re.I),
"name": name,
"open": "Open" in data[1],
"count": int(data[2].rsplit(" ", 1)[-1]),
"updated": eastern.localize(datetime.datetime.strptime(data[3][8:].strip(), '%m/%d/%Y %I:%M %p')).isoformat(),
Expand Down

0 comments on commit e6dbcc0

Please sign in to comment.