Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdoman committed May 24, 2019
2 parents 6490b3c + cf68980 commit a4673cc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion penn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.8.3'
__version__ = '1.8.5'

from .registrar import Registrar
from .directory import Directory
Expand Down
4 changes: 3 additions & 1 deletion penn/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def get_schedule(self):
def get_usage(self):
"""Get fitness locations and their current usage."""

resp = requests.get(FITNESS_URL, timeout=30)
resp = requests.get(FITNESS_URL, headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
}, timeout=30)
resp.raise_for_status()

soup = BeautifulSoup(resp.text, "html5lib")
Expand Down
8 changes: 5 additions & 3 deletions penn/studyspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,18 @@ def cancel_room(self, booking_id):
resp = self._request("POST", "/1.1/space/cancel/{}".format(booking_id))
return resp.json()

def get_reservations(self, email, date):
def get_reservations(self, email, date, timeout=None):
"""Gets reservations for a given email.
:param email: the email of the user who's reservations are to be fetched
:type email: str
"""
try:
resp = self._request("GET", "/1.1/space/bookings?email={}&date={}&limit=100".format(email, date))
except resp.exceptions.HTTPError as error:
resp = self._request("GET", "/1.1/space/bookings?email={}&date={}&limit=100".format(email, date), timeout=timeout)
except requests.exceptions.HTTPError as error:
raise APIError("Server Error: {}".format(error))
except requests.exceptions.ConnectTimeout:
raise APIError("Timeout Error")
return resp.json()

def get_reservations_for_booking_ids(self, booking_ids):
Expand Down
12 changes: 9 additions & 3 deletions penn/wharton.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ class Wharton(object):
>>> s = Wharton()
"""

def get_reservations(self, sessionid):
def get_reservations(self, sessionid, timeout=None):
"""Returns a list of location IDs and names."""
url = "{}{}".format(BASE_URL, "/reservations/")
cookies = dict(sessionid=sessionid)

try:
resp = requests.get(url, cookies=cookies)
except resp.exceptions.HTTPError as error:
resp = requests.get(url, timeout=timeout, cookies=cookies)
except requests.exceptions.HTTPError as error:
raise APIError("Server Error: {}".format(error))
except requests.exceptions.ConnectTimeout:
raise APIError("Timeout Error")

html = resp.content.decode("utf8")

Expand Down Expand Up @@ -54,6 +56,10 @@ def book_reservation(self, sessionid, roomid, start, end):
format = "%Y-%m-%dT%H:%M:%S-{}".format(self.get_dst_gmt_timezone())
booking_url = "{}/reserve/{}/{}/?d={}".format(BASE_URL, roomid, start.strftime(format), duration)
resp = requests.get(booking_url, cookies={"sessionid": sessionid})

if resp.status_code == 403:
return {"success": False, "error": "Your account does not have permission to book Wharton GSRs!"}

resp.raise_for_status()

csrfheader = re.search(r"csrftoken=(.*?);", resp.headers["Set-Cookie"]).group(1)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
url='https://github.com/pennlabs/penn-sdk-python',
author='Penn Labs',
author_email='[email protected]',
version='1.8.3',
version='1.8.5',
packages=['penn'],
license='MIT',
package_data={
Expand Down

0 comments on commit a4673cc

Please sign in to comment.