def filter_feed(url, tasks): ids = set(t.entry_id for t in tasks) feed = utils.parse_atom(url, cache=feed_cache) # feed = deepcopy(utils.parse_atom(url, cache=feed_cache)) # for element in feed.root.findall('entry'): # if element.find('id').text not in ids: # feed.root.remove(element) return feed
def process_task(self, task): """ Tries to create a new subscription from a subscription task. The task should already be verified with a subscriber. However such verification only confirms the intent of the subscriber and actual subscription may still fail for different reasons (mostly from checks in parse_atom). """ atom = utils.parse_atom(task.topic) if task.mode == "subscribe": subscription, created = self.get_or_create( callback=task.callback, topic=atom.link("self"), verify_token=task.verify_token, defaults={"secret": task.secret, "expires": datetime.now()}, ) subscription.expires = datetime.now() + timedelta(seconds=task.lease_seconds) subscription.save() else: self.filter(callback=task.callback, topic=atom.link("self")).delete()