示例#1
0
文件: crawler.py 项目: adminus/podato
def _store_podcast(podcast_data):
    """Given a list of dictionaries representing podcasts, store them all in the database."""
    if not podcast_data:
        return
    podcast = Podcast(**podcast_data)
    podcast.save()
    return podcast
示例#2
0
文件: crawler.py 项目: adminus/podato
def _store_podcast(podcast_data):
    """Given a list of dictionaries representing podcasts, store them all in the database."""
    if not podcast_data:
        return
    podcast = Podcast(**podcast_data)
    podcast.save()
    return podcast
示例#3
0
 def unsubscribe(self, podcast):
     """Unsubscribe the user from the podcast."""
     if podcast.url in self.subscriptions:
         self.run(self.table.get(self.id).update(
             {"subscriptions": r.row["subscriptions"].set_difference([podcast.url])}
         ))
         Podcast.run(Podcast.get_table().get(podcast.url).update({
             "subscribers": (r.row["subscribers"].default(0) - 1)
         }))
         return True
     return False
示例#4
0
 def subscribe(self, podcast):
     """Subscribe the user to the given podcast."""
     if podcast.url in self.subscriptions:
         return SubscribeResult(success=False)
     self.run(self.table.get(self.id).update({
         "subscriptions": r.row["subscriptions"].append(podcast.url)
     }))
     Podcast.run(Podcast.get_table().get(podcast.url).update({
         "subscribers": (r.row["subscribers"].default(0) + 1)
     }))
     return SubscribeResult(success=True)
示例#5
0
    def subscribe_multi(self, podcasts):
        """Subscribe the user to multiple podcasts. podcasts should be an iterable of Podcast objects."""
        not_already_subscribed = []
        for podcast in podcasts:
            if podcast.url not in self.subscriptions:
                not_already_subscribed.append(podcast.url)

        self.run(self.table.get(self.id).update(
            {"subscriptions": r.row["subscriptions"].set_union(not_already_subscribed)}
        ))
        Podcast.run(Podcast.get_table().get_all(r.args(not_already_subscribed)).update({
            "subscribers": (r.row["subscribers"].default(0) + 1)
        }))
        return SubscribeResult(success=True)
示例#6
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))
示例#7
0
文件: crawler.py 项目: adminus/podato
def _update_podcasts():
    to_update = Podcast.get_update_needed()
    i = 1
    for podcast in to_update:
        print "Updating the %snd podcast" % i
        i += 1
        _update_podcast.s(url=podcast.url).apply_async()
示例#8
0
文件: crawler.py 项目: adminus/podato
def _update_podcasts():
    to_update = Podcast.get_update_needed()
    i = 1
    for podcast in to_update:
        print "Updating the %snd podcast" % i
        i += 1
        _update_podcast.s(url=podcast.url).apply_async()
示例#9
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)
示例#10
0
 def unsubscribe_by_url(self, url):
     """Unsubscribe the user from the podcast at the given feed url."""
     podcast = Podcast.get_by_url(url)
     if not podcast:
         return SubscribeResult(success=False)
     return SubscribeResult(success=self.unsubscribe(podcast))
示例#11
0
 def get_subscriptions(self):
     """Get the Podcast objects of podcasts the user has subscribed to."""
     if len(self.subscriptions) == 0:
         return []
     res = self.run(Podcast.get_table().get_all(r.args(self.subscriptions)))
     return [Podcast.from_dict(p) for p in res]
示例#12
0
文件: crawler.py 项目: adminus/podato
def _make_updates(url, data):
    podcast = Podcast.get_by_url(url)
    data["previous_urls"] = list(set(podcast.previous_urls).union(data["previous_urls"]))
    podcast.update(data)
示例#13
0
文件: crawler.py 项目: adminus/podato
def _handle_moved_podcast(previous_url, data):
    Podcast.delete_by_url(previous_url)
    _store_podcast(data)
示例#14
0
文件: crawler.py 项目: adminus/podato
def _make_updates(url, data):
    podcast = Podcast.get_by_url(url)
    data["previous_urls"] = list(
        set(podcast.previous_urls).union(data["previous_urls"]))
    podcast.update(data)
示例#15
0
文件: crawler.py 项目: adminus/podato
def _handle_moved_podcast(previous_url, data):
    Podcast.delete_by_url(previous_url)
    _store_podcast(data)