def getByUsername(username): ''' Helper to find Users by username. Returns only if there is a single exact case match ''' return utils.firstOrNone( User.query.filter(User.username == username).all())
def _getBlockFromList(self, soup, selector, blockName): elems = utils.firstOrNone(soup.select(selector)) if not elems: logger.warning(f'No blocklist {selector}') return None def _isBlock(elem): return elem.text.strip().lower() == blockName detailsLabel = elems.findChild(_isBlock) if not detailsLabel: logger.warning(f'No label {blockName}') return None return detailsLabel.findNextSibling()
def _getLink(elem, base): def _matchesEventLink(link): if not link: return False try: parsed = urlparse(link) except ValueError: return False return (parsed.netloc == 'www.chemistry.gatech.edu' and parsed.path.startswith(self.LINK_PREFIX_INCLUDE)) links = elem.select(self.SELECTOR_EVENT_LINK) links = map(utils.Soup.getElemLink, links) links = map(utils.normalizeURL(base=base), links) links = filter(_matchesEventLink, links) return utils.firstOrNone(links)
def _getEventDetails(self, eventURL): details = self.requester.fetchURL(eventURL) if not details: return None soup = BeautifulSoup(details, 'html.parser') title1 = utils.Soup.getTextAt(soup, self.SELECTOR_EVENT_TITLE1) title2 = utils.Soup.getTextAt(soup, self.SELECTOR_EVENT_TITLE2) if title1 and title2: title = '%s: %s' % (title1, title2) else: title = utils.firstOrNone(filter(None, (title1, title2))) singleStr = utils.Soup.getTextAt(soup, self.SELECTOR_EVENT_TIMESINGLE) startStr = utils.Soup.getTextAt(soup, self.SELECTOR_EVENT_TIMESTART) endStr = utils.Soup.getTextAt(soup, self.SELECTOR_EVENT_TIMEEND) startTime, endTime = self._parseEventTime(singleStr, startStr, endStr) startTime = utils.normalizeDate(startTime, self.config['defaults']['timezone']) event = RawEvent(self.IDENTIFIER, eventURL, title, startTime) event.setEnd( utils.normalizeDate(endTime, self.config['defaults']['timezone'])) event.setLocation( utils.Soup.getTextAt(soup, self.SELECTOR_EVENT_LOCATION)) description, links = utils.Soup.tokenizeElemAt( soup, self.SELECTOR_EVENT_DESCRIPTION, base=eventURL) links |= set(utils.Soup.getLinksAt(soup, self.SELECTOR_EVENT_LINKS)) links = map(utils.normalizeURL(base=eventURL), links) links = set(filter(None, links)) event.setDescription(description) event.setLinks(links) return event
def getByOAuthId(oauth_uid): return utils.firstOrNone( FacebookUser.query.filter( FacebookUser.oauth_uid == oauth_uid).all())
def getById(id): ''' Helper to find Users by id. Returns only if there is a single exact case match ''' return utils.firstOrNone(User.query.filter(User.id == id).all())
def getByEmail(email): ''' Helper to find Users by email. Returns only if there is a single exact case match ''' return utils.firstOrNone(User.query.filter(User.email == email).all())
def getByOAuthId(oauth_uid): return utils.firstOrNone(FacebookUser.query.filter(FacebookUser.oauth_uid == oauth_uid).all())
def getByUsername(username): ''' Helper to find Users by username. Returns only if there is a single exact case match ''' return utils.firstOrNone(User.query.filter(User.username == username).all())