Пример #1
0
	def insert(cls, topic_list, source_dict=None):
		"""Inserts a set of FeedToFetch entities for a set of topics.

		Overwrites any existing entities that are already there.

		Args:
			topic_list: List of the topic URLs of feeds that need to be fetched.
			source_dict: Dictionary of sources for the feed. Defaults to an empty
				dictionary.
		"""
		if not topic_list:
			return

		if source_dict:
			source_keys, source_values = zip(*source_dict.items())	# Yay Python!
		else:
			source_keys, source_values = [], []

		feed_list = [
				cls(key_name=utils.get_hash_key_name(topic),
						topic=topic,
						source_keys=list(source_keys),
						source_values=list(source_values))
				for topic in set(topic_list)]
		db.put(feed_list)
		# TODO(bslatkin): Use a bulk interface or somehow merge combined fetches
		# into a single task.
		for feed in feed_list:
			feed._enqueue_task()
Пример #2
0
	def create_key(cls, topic):
		"""Creates a key for a KnownFeed.

		Args:
			topic: The feed's topic URL.

		Returns:
			Key instance for this feed.
		"""
		return datastore_types.Key.from_path(cls.kind(), utils.get_hash_key_name(topic))
Пример #3
0
	def create(cls, topic):
		"""Creates a new KnownFeed.

		Args:
			topic: The feed's topic URL.

		Returns:
			The KnownFeed instance that hasn't been added to the Datastore.
		"""
		return cls(key_name=utils.get_hash_key_name(topic), topic=topic)
Пример #4
0
	def create_key_name(topic):
		"""Creates a key name for a FeedRecord for a topic.

		Args:
			topic: The topic URL for the FeedRecord.

		Returns:
			String containing the key name.
		"""
		return utils.get_hash_key_name(topic)
Пример #5
0
	def create_key_name(callback, topic):
		"""Returns the key name for a Subscription entity.

		Args:
			callback: URL of the callback subscriber.
			topic: URL of the topic being subscribed to.

		Returns:
			String containing the key name for the corresponding Subscription.
		"""
		return utils.get_hash_key_name(u'%s\n%s' % (callback, topic))