def get_feed(feed_id): """ Retrieve a feed from memcache or generate it if it does not exist """ xml = memcache.get(feed_id) # In memcache? if xml is None: feed = Feed.get_by_id(int(feed_id)) rss = None if feed: if feed.public_board: rss = TrelloRSS( constants.KEY, channel_title=feed.channel_title, rss_channel_link=feed.channel_link, description=feed.channel_description) else: user = feed.user.get() rss = TrelloRSS( constants.KEY, token=user.auth_token, channel_title=feed.channel_title, rss_channel_link=feed.channel_link, description=feed.channel_description) if feed.get_all: if feed.actions: rss.get_all(items=feed.actions) else: rss.get_all() else: if feed.actions: rss.get_from(feed.board_id,public_board=feed.public_board,items=feed.actions) else: rss.get_from(feed.board_id,public_board=feed.public_board) xml = rss.rss memcache.add(key=feed_id, value=xml, time=1800) # Expire after 30 minutes return xml
def validate_input(board_id,link): """ Validate whether a board id is correct, and whether a link is correct """ errors = [] try_url = re.match(url_re, board_id) if try_url: board_id = try_url.group(1) trell = TrelloRSS(constants.KEY) try: trell.get_from(board_id, public_board=True) except ResourceUnavailable: errors.append('iderror') if not re.match(url_regex, link): errors.append('link') return board_id, link, errors