Ejemplo n.º 1
0
	def put_buffer(self, buffer):
		station = self.station
		new_timestamp = buffer['timestamp']
		new_broadcasts = buffer['broadcasts']

		#Retrieving broadcasts from datastore
		key_names = []
		for i in xrange(0,len(new_broadcasts)):
			b = new_broadcasts[i]
			key_names.append(b['key_name'])

		broadcasts = Broadcast.get_by_key_name(key_names)
		b_keys = []

		for i in xrange(0,len(broadcasts)):
			b_key = broadcasts[i]
			b_keys.append(b_key.key())

		station.timestamp = new_timestamp
		station.broadcasts = b_keys
		station.active = datetime.utcnow()
		station.put()
		logging.info("Buffer put in datastore")

		self._buffer = {
			'broadcasts':new_broadcasts,
			'timestamp': new_timestamp
		}
		memcache.set(self._memcache_station_id, station)
		logging.info("Station updated in memcache")
		
		memcache.set(self._memcache_station_buffer_id, self._buffer)
		logging.info("Buffer updated in memcache")
Ejemplo n.º 2
0
	def get(self, key_name):
		broadcast = Broadcast.get_by_key_name(key_name)
		
		if(broadcast):
			m = re.match(r"(\w+).(\w+)", key_name)
			shortname = m.group(1)			
			self.station_proxy = StationApi(shortname)
			
			user_agent = self.request.headers["User-Agent"]
			facebook_agent = "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
			
			if(user_agent != facebook_agent):
				# Redirect to station
				self.redirect("/" + shortname)
			else:
				# Facebook linter
				station = self.station_proxy.station
				template_values = {
					"broadcast" : broadcast,
				}
				self.render("station/facebook/broadcast.html", template_values)
		else:
			# 404 error
			self.render("station/404.html", None)