Exemple #1
0
 def subscribe_by_url(self, url):
     """Subscribe the user to the podcast at the given feed url."""
     podcast = Podcast.get_by_url(url)
     if podcast == None:
         id = crawler.fetch(url, subscribe=self).id
         SubscribeResult(id=id)
     return SubscribeResult(success=self.subscribe(podcast))
Exemple #2
0
    def get_or_fetch(cls, url, **kwargs):
        """Get a podcast by its feed url. If it's not in the db, fetch it."""
        p = cls.get_by_url(url)
        if not p:
            logging.debug("Not in the database, need to fetch.")
            code = error_store.get_error(url)
            if code:
                logging.debug("Refusing to fetch, because we've encountered an error recently: %s" % code)
                return None

            # Doing this import inside a function to avoid circular import.
            from webapp.podcasts import crawler

            results = list(crawler.fetch(url).results[0].collect())
            logging.debug("Fetched, got %s." % results)
            p = cls.get_by_url(url, **kwargs)
        return p
Exemple #3
0
    def get_or_fetch(cls, url, **kwargs):
        """Get a podcast by its feed url. If it's not in the db, fetch it."""
        p = cls.get_by_url(url)
        if not p:
            logging.debug("Not in the database, need to fetch.")
            code = error_store.get_error(url)
            if code:
                logging.debug(
                    "Refusing to fetch, because we've encountered an error recently: %s"
                    % code)
                return None

            # Doing this import inside a function to avoid circular import.
            from webapp.podcasts import crawler
            results = list(crawler.fetch(url).results[0].collect())
            logging.debug("Fetched, got %s." % results)
            p = cls.get_by_url(url, **kwargs)
        return p
Exemple #4
0
    def subscribe_multi_by_url(self, urls):
        """Subscribe the user to all the podcasts at the given feed urls. urls should be an iterable of strings."""
        podcasts = Podcast.get_multi_by_url(urls)
        already_fetched = []
        to_fetch = []
        for url in urls:
            if url in podcasts:
                already_fetched.append(podcasts[url])
            else:
                to_fetch.append(url)

        if already_fetched:
            self.subscribe_multi(already_fetched)

        res = None
        success = None
        if to_fetch:
            id = crawler.fetch(to_fetch, subscribe=self).id
            return SubscribeResult(id=id)
        else:
            return SubscribeResult(success=True)