From 8063002a4b4ade6c144026cbd445a5201c52f702 Mon Sep 17 00:00:00 2001 From: Eva Killenberg Date: Fri, 8 Feb 2019 18:04:20 -0500 Subject: [PATCH 1/2] integrated wharton endpoint --- penn/wharton.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/penn/wharton.py b/penn/wharton.py index 05e20d6..255cfb5 100644 --- a/penn/wharton.py +++ b/penn/wharton.py @@ -3,6 +3,7 @@ from bs4 import BeautifulSoup from .base import APIError +from flask import jsonify, request BASE_URL = "https://apps.wharton.upenn.edu/gsr" @@ -44,3 +45,65 @@ def get_reservations(self, sessionid): } reservations.append(reservation) return reservations + + def get_wharton_gsrs(self, sessionid): + time = request.args.get('date') + if time: + time += " 05:00" + else: + time = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%S") + resp = requests.get('https://apps.wharton.upenn.edu/gsr/api/app/grid_view/', params={ + 'search_time': time + }, cookies={ + 'sessionid': sessionid + }) + if resp.status_code == 200: + return resp.json() + else: + return {'error': 'Remote server returned status code {}.'.format(resp.status_code)} + + def switch_format(self, gsr): + if "error" in gsr: + return gsr + rooms = { + "cid": 1, + "name": "Huntsman Hall", + "rooms": [] + } + + for time in gsr["times"]: + for entry in time: + entry["name"] = "GSR " + entry["room_number"] + del entry["room_number"] + time = { + "available": entry["reserved"], + "end": entry["end_time"], + "start": entry["start_time"] + } + exists = False + for room in rooms["rooms"]: + if room["name"] == entry["name"]: + room["times"].append(time) + exists = True + if not exists: + del entry["booked_by_user"] + del entry["building"] + if "reservation_id" in entry: + del entry["reservation_id"] + entry["lid"] = 1 + entry["capacity"] = 5 + # entry["gid"] = null + # entry["thumbnail"] = null; + # entry["description"] = null + entry["room_id"] = entry["id"] + del entry["id"] + entry["times"] = [time] + del entry["reserved"] + del entry["end_time"] + del entry["start_time"] + rooms["rooms"].append(entry) + return {"categories": [rooms]} + + def get_wharton_gsrs_formatted(self, sessionid): + gsrs = self.get_wharton_gsrs(sessionid) + return self.switch_format(gsrs) From eb2b3c5633eca7e498cabf5463e79c95c5df56b1 Mon Sep 17 00:00:00 2001 From: Eva Killenberg Date: Sun, 10 Feb 2019 12:58:10 -0500 Subject: [PATCH 2/2] remove flask --- penn/wharton.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/penn/wharton.py b/penn/wharton.py index 255cfb5..c95cb27 100644 --- a/penn/wharton.py +++ b/penn/wharton.py @@ -3,8 +3,6 @@ from bs4 import BeautifulSoup from .base import APIError -from flask import jsonify, request - BASE_URL = "https://apps.wharton.upenn.edu/gsr" @@ -46,7 +44,7 @@ def get_reservations(self, sessionid): reservations.append(reservation) return reservations - def get_wharton_gsrs(self, sessionid): + def get_wharton_gsrs(self, sessionid, request): time = request.args.get('date') if time: time += " 05:00"