def parse_holds(self, response): table_header = response.find("tr", attrs={"class": "patFuncHeaders"}) if not table_header: return [] headers = [th.string.strip() for th in table_header("th")] entries = [] for row in table_header.findNextSiblings("tr"): entry = Hold(self.library, self.card) i = 0 for cell in row.findAll(td_or_th_regex): column_name = headers[i] if column_name == "TITLE": self.parse_title(cell, entry) elif column_name == "PICKUP LOCATION": if cell.select: all_selected = cell.select.findAll("option", selected="selected") if all_selected: pickup = all_selected[0].string else: pickup = "" else: pickup = cell.string # make sure we clean up the string # also ensures that we're saving a true string, # not a NaviagableString, which pickles terribly! entry.pickup = str(pickup).strip() elif column_name == "STATUS": entry.status = parse_hold_status(cell) elif column_name == "CANCEL IF NOT FILLED BY": try: entry.expires = parse_hold_expires(cell) except: # noqa E722 - do not use bare except # expiration info isn't critical - ignore pass elif column_name == "FREEZE": try: if parse_hold_frozen(cell): entry.freeze() except: # noqa E722 - do not use bare except # frozen info isn't critical - ignore logging.warn("error getting frozen info", exc_info=True) pass i += 1 entries.append(entry) return entries
def parse_holds(self, response): table_header = response.find('tr', attrs={'class': 'patFuncHeaders'}) if not table_header: return [] headers = [th.string.strip() for th in table_header('th')] entries = [] for row in table_header.findNextSiblings('tr'): entry = Hold(self.library, self.card) i = 0 for cell in row('td'): column_name = headers[i] if column_name == 'TITLE': self.parse_title(cell, entry) elif column_name == 'PICKUP LOCATION': if cell.select: pickup = cell.select.findAll('option', selected='selected')[0].string else: pickup = cell.string # make sure we clean up the string # also ensures that we're saving a true string, # not a NaviagableString, which pickles terribly! entry.pickup = str(pickup).strip() elif column_name == 'STATUS': entry.status = parse_hold_status(cell) elif column_name == 'CANCEL IF NOT FILLED BY': try: entry.expires = parse_hold_expires(cell) except: # expiration info isn't critical - ignore pass elif column_name == 'FREEZE': try: if parse_hold_frozen(cell): entry.freeze() except: # frozen info isn't critical - ignore logging.warn('error getting frozen info', exc_info=True) pass i += 1 entries.append(entry) return entries
def parse_holds(self, response): table_header = response.find('tr', attrs={'class': 'patFuncHeaders'}) if not table_header: return [] headers = [th.string.strip() for th in table_header('th')] entries = [] for row in table_header.findNextSiblings('tr'): entry = Hold(self.library, self.card) i = 0 for cell in row('td'): column_name = headers[i] if column_name == 'TITLE': self.parse_title(cell, entry) elif column_name == 'PICKUP LOCATION': if cell.select: pickup = cell.select.findAll('option', selected='selected')[0].string else: pickup = cell.string # make sure we clean up the string # also ensures that we're saving a true string, # not a NaviagableString, which pickles terribly! entry.pickup = str(pickup).strip() elif column_name == 'STATUS': entry.status = parse_hold_status(cell) elif column_name == 'CANCEL IF NOT FILLED BY': try: entry.expires = parse_hold_expires(cell) except: # noqa E722 - do not use bare except # expiration info isn't critical - ignore pass elif column_name == 'FREEZE': try: if parse_hold_frozen(cell): entry.freeze() except: # noqa E722 - do not use bare except # frozen info isn't critical - ignore logging.warn('error getting frozen info', exc_info=True) pass i += 1 entries.append(entry) return entries
def parse_holds(self, holds_soup): holds = [] holds_rows = holds_soup.findAll('tr', {'class': 'pickupHoldsLine'}) for row in holds_rows: title = row('td')[2].find('a').string author = row('td')[2].find('p').find(text=True) is_frozen = row('td')[3].string == 'Suspended' pickup = row('td')[4].string rank = int(row('td')[6].string) logging.debug('%s / %s / %s', title, author, rank) hold = Hold(self.library, self.card) hold.title = title hold.author = author hold.pickup = pickup hold.status = self.parse_status(row) if is_frozen: hold.freeze() holds.append(hold) return holds
def parse_holds(self, holds_soup): holds = [] holds_rows = holds_soup.findAll('tr', {'class': 'pickupHoldsLine'}) for row in holds_rows: title = row('td')[2].find('a').string author = row('td')[2].find('p').find(text=True) is_frozen = row('td')[3].string == 'Suspended' pickup = row('td')[4].string rank = int(row('td')[6].string) logging.debug('%s / %s / %s', title, author, rank) hold = Hold(self.library, self.card) hold.title = title hold.author = author hold.pickup = pickup hold.status = self.parse_status(row) if is_frozen: hold.freeze() holds.append(hold) return holds