Skip to content

Commit

Permalink
fix reservation deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ezwang committed Feb 10, 2019
1 parent a882f6b commit 30d0db9
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions penn/wharton.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import requests
import datetime

from bs4 import BeautifulSoup
from .base import APIError
Expand Down Expand Up @@ -47,11 +46,11 @@ def get_reservations(self, sessionid):

def delete_booking(self, sessionid, booking_id):
"""Returns a list of location IDs and names."""
url = "{}{}{}".format(BASE_URL, "/delete/", booking_id)
url = "{}{}{}/".format(BASE_URL, "/delete/", booking_id)
cookies = dict(sessionid=sessionid)

try:
resp = requests.get(url, cookies=cookies)
resp = requests.get(url, cookies=cookies, headers={'Referer': '{}{}'.format(BASE_URL, "/reservations/")})
except resp.exceptions.HTTPError as error:
raise APIError("Server Error: {}".format(error))

Expand All @@ -62,26 +61,19 @@ def delete_booking(self, sessionid, booking_id):
if "https://weblogin.pennkey.upenn.edu" in html:
raise APIError("Wharton Auth Failed. Session ID is not valid.")

resp.raise_for_status()

soup = BeautifulSoup(html, "html5lib")
middleware_token = soup.find("input", {'name': "csrfmiddlewaretoken"}).get('value')

csrftoken = resp.cookies['csrftoken']
cookies2 = {'sessionid': sessionid, 'csrftoken': csrftoken}

reservationsUrl = "{}{}".format(BASE_URL, "/reservations")
headers = {'Referer': reservationsUrl}

headers = {'Referer': url}
payload = {'csrfmiddlewaretoken': middleware_token}

print(csrftoken)
print(middleware_token)
print(headers)
print(payload)
try:
resp2 = requests.post(url, cookies=cookies2, data=payload, headers = headers)
except resp.exceptions.HTTPError as error:
resp2 = requests.post(url, cookies=cookies2, data=payload, headers=headers)
except resp2.exceptions.HTTPError as error:
raise APIError("Server Error: {}".format(error))

print(resp2.content.decode("utf8"))

return "success"

0 comments on commit 30d0db9

Please sign in to comment.