示例#1
0
    def save_newest_items(self):
        """
		Get list of item dicts from the newest items by id
		Includes all acceptable kinds of items (ignores pollopts)
		Saves items in order of ascending ID – important for parent_id and root_id references
		"""

        # Get latest item ids from db and from api
        max_api_id = self.fetch_max_item_id()
        max_db_id = Status.get_max_item_id()

        # If no new data, quit. We don't want to use this function to update items
        if (max_api_id <= max_db_id):
            return

        # Save latest items and update max id
        save = lambda item_data: self.save_item(item_data, update_max_id=True)
        self.fetch_items(range(max_db_id + 1, max_api_id), callback=save)
示例#2
0
文件: scraper.py 项目: raquo/hnapp
	def save_newest_items(self):
		"""
		Get list of item dicts from the newest items by id
		Includes all acceptable kinds of items (ignores pollopts)
		Saves items in order of ascending ID – important for parent_id and root_id references
		"""
		
		# Get latest item ids from db and from api
		max_api_id = self.fetch_max_item_id()
		max_db_id = Status.get_max_item_id()
		
		# If no new data, quit. We don't want to use this function to update items
		if (max_api_id <= max_db_id):
			return
		
		# Save latest items and update max id
		save = lambda item_data: self.save_item(item_data, update_max_id=True)
		self.fetch_items(range(max_db_id+1, max_api_id), callback=save)