Library Website Scraper

This documentation explains the methods of the StudySpaces object. This SDK module is implemented by scraping the Penn Libraries LibCal website.

class penn.studyspaces.StudySpaces[source]

Used for interacting with the UPenn library GSR booking system.

Usage:

>>> from penn import StudySpaces
>>> s = StudySpaces()
book_room(building, room, start, end, firstname, lastname, email, groupname, phone, size, fake=False)[source]

Books a room given the required information.

Parameters:
  • building (int) – The ID of the building the room is in.
  • room (int) – The ID of the room to book.
  • start (datetime) – The start time range of when to book the room.
  • end (datetime) – The end time range of when to book the room.
  • fake (bool) – If this is set to true, don’t actually book the room. Default is false.
Returns:

Boolean indicating whether the booking succeeded or not.

Raises:

ValueError – If one of the fields is missing or incorrectly formatted, or if the server fails to book the room.

get_buildings()[source]

Returns a list of building IDs, building names, and services.

static get_room_id_name_mapping(building)[source]

Returns a dictionary mapping id to name, thumbnail, and capacity.

The dictionary also contains information about the lid and gid, which are used in the booking process.

Parameters:building (int) – The ID of the building to fetch rooms for.
Returns:A list of rooms, with each item being a dictionary that contains the room id and available times.
get_rooms(building, start, end)[source]

Returns a dictionary matching all rooms given a building id and a date range.

The resulting dictionary contains both rooms that are available and rooms that already have been booked.

Parameters:
  • building (int) – The ID of the building to fetch rooms for.
  • start (datetime) – The start date of the range used to filter available rooms.
  • end (datetime) – The end date of the range used to filter available rooms.
static parse_date(date)[source]

Converts library system dates into timezone aware Python datetime objects.

Parameters:date (datetime) – A library system date in the format ‘2018-01-25 12:30:00’.
Returns:A timezone aware python datetime object.