Ejemplo n.º 1
0
	def toEntry(self, video):
		e = Entry()
		if video.title != None:
			e.title = video.title.text.decode('UTF-8')
		if video.content != None:
			if video.media.content != None:
				e.text = '<div class="video">' + self.getFlashPlayerHTML( video.media.content[0].url ) + '</div>' 
			if video.content.text != None:
				e.text += video.content.text.decode('UTF-8')

		e.source = self.source_id
		e.external_id = video.id.text
		e.created = parse( video.published.text )
		e.url = video.link[0].href
	
		if video.media.keywords != None:
			# split the tags 
			e.tags = video.media.keywords.text.decode('UTF-8').replace(' ','').split(',')
			
			
		# save the location data if available
		if video.geo:
			e.lat = str(video.geo.latitude())
			e.lng = str(video.geo.longitude())
			
		return e
Ejemplo n.º 2
0
	def _addNewEntry(self, form):
		if form.is_valid():
			# validation successful, we can save the data
			e = Entry()
			e.title = form.clean_data['title']
			e.text = form.clean_data['text']
			e.tags = form.clean_data['tags'].split(' ')
			e.lat = form.clean_data['lat']
			if e.lat == "":
				e.lat = None
			e.lng = form.clean_data['lng']			
			if e.lng == "":
				e.lng = None
			e.source = 'blog'
			e.put()
			
			e = Entry.get(e.key())
			
			# reset the data cache since there's new content
			from google.appengine.api import memcache
			memcache.flush_all()			

			# return successful creation
			view_data = {
				'message': 'New blog entry added successfully. <a href="%s">Link to the entry</a>.' % e.permalink(), 
				'error': False,
				'entry_link': e.permalink(),							
				'entry': e
			}
			self.writeResponse(view_data)

		else:
			# form not valid, must show again with the errors
			data = { 'error': True, 'errors': {}}
			# (the Form object is actually iterable)
			for field in form:
				if field.errors:
					data['errors'][field.name] = field.errors

			self.writeResponse(data)
Ejemplo n.º 3
0
 def toEntry(self, item):
     e = Entry()
     e.external_id = item.id 
     e.created = item.created_time
     e.source = self.source_id
     e.url = item.link
     e.title = item.caption.text
     e.text = self.makeInstagramText(item)
     
     # save the location data in case it's got any
     if 'location' in dir(item):
         e.lat = "%.15f" % item.location.point.latitude
         e.lng = "%.15f" % item.location.point.longitude
         e.location_name = item.location.name
     
     return e
Ejemplo n.º 4
0
	def post(self):
		form = EntryForm( self.request.POST )
		if form.is_valid():
			# validation successful, we can save the data
			e = Entry()
			print(form.clean_data)
			e.title = form.clean_data['title']
			e.text = form.clean_data['text']
			e.tags = form.clean_data['tags'].split(' ')
			e.lat = form.clean_data['lat']
			e.lng = form.clean_data['lng']
			e.source = 'blog'
			e.put()
			
			# redirect to the main page
			self.redirect( '/' )
		else:
			# form not valid, must show again with the errors
			self.writeResponse( 'new_blog_post.html', { 'form': form.render() } )
Ejemplo n.º 5
0
	def toEntry(self, status):
		from app.utils import StringHelper			
		e = Entry(external_id=str(status['id']),
		source = self.source_id,
		text = Utils.links_to_anchors(Utils.twitpic_to_img(status['text'])),
		title = StringHelper().remove_new_lines(status['text']),
		url='http://twitter.com/' + str(status['user']['screen_name']) + '/statuses/' + str(status['id']))
		e.created = parse(status['created_at'])
		
		# extract the tags
		e.tags = StringHelper().extract_twitter_tags(status['text'])
		
		# process the location coordinates if they're available
		if status['coordinates'] != None:
			e.lat = str(status['coordinates']['coordinates'][1])
			e.lng = str(status['coordinates']['coordinates'][0])	
			
		# is this entry a reply-to?
		logging.debug(e.text[0])
		e.twitter_reply = (e.text[0] == '@')
		
		return(e)