Beispiel #1
0
	def get(self):
		from main import User, Page, get_hash
		max_check = 100
		max_tweet = 1
		if self.is_developer():
			max_check = 1
		visited_users = set()
		visited_page = 0
		tweet_made = 0
		conti = True
		for page in Page.all().order('modified'):
			if not conti:
				break
			self.debug('%d-th page' % visited_page)
			user_id, url = page.key().name().split()
			self.debug('Page(user=%s, url=%s)' % (user_id, url))
			if user_id in visited_users:
				self.debug("don't tweet more than once from a user per a cron job.")
				continue

			visited_page += 1
			if visited_page == max_check:
				self.debug('will be the last to process')
				conti = False
			content = get_hash(url)
			if content != '' and page.content != content:
				page.content = content
				self.tweet(User.get_by_key_name(user_id), url)
				tweet_made += 1
				if tweet_made == max_tweet:
					self.debug('the last to tweet')
					conti = False
				visited_users.add(user_id)
			else:
				self.debug('no update detected in %s' % url)
			page.put()
		else:
			self.debug('checked all pages. terminate.')
			return
		self.debug('processed %d pages, tweeting %d times. terminate.' % (visited_page, tweet_made))