コード例 #1
0
class BaseParser(object):
    """
    The basic parser that will be inherited by all. Provides an ingestion
    interface
    """
    
    def __init__(self, listing):
        """
        Constructor requires a listing massaged in from the an rssfeed
        """
        self.listing = listing
        self.soup = BeautifulSoup(urllib.urlopen(self.listing['url']).read())
        self.api = CyblerAPI()

    @property
    def valid(self):
        raise NotImplementedError()

    def _parse_soup(self):
        raise NotImplementedError()
        
    def ingest(self):
        """
        The actual ingestion code
        """
        #Use the soup to modify the listing
        self._parse_soup()
        #Check if the listing is valid and update via the API
        if self.valid:
            self.api.insert(ASSOCIATED_RESOURCE, self.listing)