Example #1
0
        def post(self):
		        broadcaster = BroadcastMessage()
                        userUtil = UserUtils()
			title = self.request.get('title', None)
			link = self.request.get('link', None)
			domain = self.request.get('domain', None)
                        user_id = self.request.get('user_id', None)
                        updated = self.request.get('updated', None)
                        embeded = self.request.get('e', None)
                        link_category = self.request.get('link_category', None)
                        subscribers = simplejson.loads(self.request.get('subscribers', None))

			message = Message( title = title, link = link , domain = domain)

                        user = SessionModel.gql('WHERE __key__ = :1', db.Key(user_id)).get()
                        if user is None:
                                logging.info('can\'t determine user by id: %s' % user_id)
                                return
                        logging.info('user %s' % user.instaright_account)
                        avatar = userUtil.getAvatar(user.instaright_account)
                        logging.info('avatar %s' %avatar)
                        messageAsJSON = [{'u':{'id':user_id, 't':title,'ol':link, 'l':LinkUtils.generate_instaright_link(user.url_encode26, LinkUtils.make_title(title)),'d':domain,'dd': LinkUtils.generate_domain_link(domain), 'a':avatar, 'u':updated, 'source': user.client, 'lc':link_category, 'html_lc':LinkUtils.getLinkCategoryHTML(user),  'e': embeded, 'n': int(time.mktime(datetime.datetime.now().timetuple()))}}]
                        logging.info('sending message %s ' %messageAsJSON)
			broadcaster.send_message(messageAsJSON)
			xmpp_handler.send_message(subscribers, message)
Example #2
0
        def get(self, domain):
                format=self.request.get('format',None)
                if domain is None or len(domain) == 0:
                        logging.info('not category in request. return empty')
                        return
                if format == 'json':
                        logging.info('domain %s json feed' % domain)
                        userUtil = UserUtils()
                        entries = SessionModel.gql('WHERE domain = :1 order by date desc', domain).fetch(10)
			self.response.headers['Content-Type'] = "application/json"
			#TODO insert categories for domain's view
                        self.response.out.write(simplejson.dumps(entries, default=lambda o: {'u':{'id':str(o.key()), 't':unicode(o.title), 'l': LinkUtils.generate_instaright_link(o.url_encode26, LinkUtils.make_title(o.title), o.url), 'user': urllib.unquote(o.instaright_account), 'source': o.client, 'html_lc':LinkUtils.getLinkCategoryHTML(o), 'd': o.domain, 'lc': LinkUtils.getLinkCategory(o), 'dd':LinkUtils.generate_domain_link(o.domain), 'u': o.date.strftime("%Y-%m-%dT%I:%M:%SZ"), 'a':userUtil.getAvatar(o.instaright_account),'ol':o.url}}))
			return
                self.response.headers['Content-Type'] = "application/json"
                self.response.out.write("[{}]")
Example #3
0
        def post(self):
                category=self.request.get('category', None)
                url_hash=self.request.get('url', None)
                userUtil=UserUtils()
                if category is None or len(category) == 0:
                        logging.info('no category in request. skipping ...')
                        return
                if url_hash is None:
                        logging.info('no url in request. skipping ...')
                        return
                model = SessionModel.gql('WHERE url_hash = :1 order by date desc', url_hash).get()
                if model is None:
                        logging.error('no session model for url hash %s ' %url_hash)
                        return

                category_path='/category/%s' %category
		broadcaster = BroadcastMessage()
                date_published=''
                if model.date is not None:
                        date_published=model.date.strftime("%Y-%m-%dT%I:%M:%SZ")
                        
                messageAsJSON = [{'u':{'id':str(model.key()), 't':unicode(model.title),'l':model.url,'d':model.domain,'u': date_published, 'a':userUtil.getAvatar(model.instaright_account),'ol':model.url,'c':category, 'lc':category}}]
                logging.info('sending category message %s for users on path %s' % (messageAsJSON, category_path))
                broadcaster.send_message(messageAsJSON,category_path)
Example #4
0
        def get(self, category):
                format=self.request.get('format',None)
                if category is None or category == 0:
                        logging.info('not category in request. return empty')
                        return
                if format == 'json':
                        logging.info('catefory %s json feed' % category)
                        userUtil = UserUtils()
                        allentries = LinkCategory.gql('WHERE category = :1 order by updated desc', category).fetch(50)
                        entries= [ e for e in allentries if hasattr(e,'model_details') and e.model_details is not None ]
                        entries = entries[:10]
			self.response.headers['Content-Type'] = "application/json"
                        self.response.out.write(simplejson.dumps(entries, default=lambda o: {'u':{'id':str(o.model_details.key()), 't':unicode(o.model_details.title), 'dd': LinkUtils.generate_domain_link(o.model_details.domain),'l':LinkUtils.generate_instaright_link(o.model_details.url_encode26, LinkUtils.make_title(o.model_details.title), o.model_details.url), 'd':o.model_details.domain, 'user': urllib.unquote(o.model_details.instaright_account), 'source': o.model_details.client, 'html_lc':LinkUtils.getLinkCategoryHTML(o), 'u': o.updated.strftime("%Y-%m-%dT%I:%M:%SZ"), 'a':userUtil.getAvatar(o.model_details.instaright_account),'ol':o.url,'c':category, 'lc':LinkUtils.getLinkCategory(o.model_details)}}))
			return
                self.response.headers['Content-Type'] = "application/json"
                self.response.out.write("[{}]")
Example #5
0
	def get(self, url_hash, title):
                try:
                        self.redirect_perm()
                        self.get_user()
                        url_hash = urllib.unquote(url_hash)
		        logging.info('url hash: %s' % url_hash)
                        logging.info('category screen_name %s' %self.screen_name)
			category=None
                        if self.avatar is None:
                                self.avatar='/static/images/noavatar.png'

                        sessionModel = SessionModel.gql('where url_encode26 = :1', url_hash).get()
                        if sessionModel is None:
                                logging.info('not article with hash %s ... redirecting' % url_hash)
                                self.redirect('/')
                                return
                        generated_title =  LinkUtils.make_title(sessionModel.title)
                        if title != generated_title:
                                self.redirect('/article/'+url_hash+'/'+generated_title)
                                return
                        instaright_link =  LinkUtils.generate_instaright_link(url_hash, generated_title)
                        links = Links.gql('where url_hash = :1', url_hash).get()
			userUtil = UserUtils()
                        if links is not None:
                                category = links.categories
                        sessionTitle = LinkUtils.generateUrlTitle(sessionModel.title)
                        template_variables = {'page_footer': PageUtils.get_footer(), 'user':self.screen_name, 'logout_url':'/account/logout', 'avatar':self.avatar,'story_avatar': userUtil.getAvatar(sessionModel.instaright_account), 'story_user': sessionModel.instaright_account, 'domain': sessionModel.domain, 'title':sessionModel.title, 'link': sessionModel.url, 'updated':sessionModel.date, 'id': str(sessionModel.key()), 'instaright_link': instaright_link, 'category': LinkUtils.getLinkCategoryHTML(sessionModel), 'dd': LinkUtils.generate_domain_link(sessionModel.domain)}
		        path = os.path.join(os.path.dirname(__file__), 'templates/article.html')
                        self.response.headers["Content-Type"] = "text/html; charset=utf-8"
		        self.response.out.write(template.render(path, template_variables))
                except:
                        e,e0 = sys.exc_info()[0], sys.exc_info()[1]
                        logging.error('handled error : %s, %s ' %( e, e0 ))
		        self.redirect('/')
Example #6
0
	def get(self):
                memcache_key='feed_json_cache'
                cached_feed= memcache.get(memcache_key)
		format = self.request.get('format', None);
                cache_exp = datetime.datetime.now() + datetime.timedelta(minutes=5)
                cache_exp_ts = time.mktime(cache_exp.timetuple())
                userUtil = UserUtils()
                if format == 'json' and cached_feed:
			logging.info('getting json from cache')
			self.response.headers['Content-Type'] = "application/json"
                        self.response.out.write(simplejson.dumps(cached_feed, default=lambda o: {'u':{'id':str(o.key()), 't':unicode(o.title), 'dd': LinkUtils.generate_domain_link(o.domain), 'd':o.domain, 'user': urllib.unquote(o.instaright_account), 'source': o.client, 'u': int(time.mktime(o.date.timetuple())), 'l':LinkUtils.generate_instaright_link(o.url_encode26,LinkUtils.make_title(o.title)),'a':userUtil.getAvatar(o.instaright_account),'ol':o.url, 'lc':LinkUtils.getLinkCategory(o), 'html_lc':LinkUtils.getLinkCategoryHTML(o), 'e': o.embeded, 'n': int(time.mktime(datetime.datetime.now().timetuple()))}}))
                        return
		entries = SessionModel.gql('ORDER by date DESC').fetch(10)
		memcache.set(memcache_key, entries, time = cache_exp_ts)
		if not entries:
			self.response.out.write('Nothing here')
		#now = datetime.datetime.now().strftime("%Y-%m-%dT%H\:%i\:%sZ")
		if format is None or format == 'xml' or format == 'valid_xml':
                        updated_entries = [ (str(o.key()), unicode(o.title), LinkUtils.generate_domain_link(o.domain), LinkUtils.generate_instaright_link(o.url_encode26,LinkUtils.make_title(o.title)),userUtil.getAvatar(o.instaright_account), o.date, LinkUtils.generate_instaright_link(o.url_encode26,LinkUtils.make_title(o.title)) ) for o in entries ]
                        template_variables = { 'entries' : updated_entries, 'dateupdated' : datetime.datetime.today()}
                        if format == 'valid_xml':
			        path= os.path.join(os.path.dirname(__file__), 'templates/feed_valid.html')
                        else:
			        path= os.path.join(os.path.dirname(__file__), 'templates/feed.html')
			self.response.headers['Content-Type'] = "application/atom+xml"
			self.response.out.write(template.render(path,template_variables))
			return
		if format == 'json':
			self.response.headers['Content-Type'] = "application/json"
                        self.response.out.write(simplejson.dumps(entries, default=lambda o: {'u':{'id':str(o.key()), 't':unicode(o.title), 'dd': LinkUtils.generate_domain_link(o.domain), 'd':o.domain, 'user': o.instaright_account, 'u': int(time.mktime(o.date.timetuple())), 'l':LinkUtils.generate_instaright_link(o.url_encode26,LinkUtils.make_title(o.title)), 'a':userUtil.getAvatar(o.instaright_account),'ol':o.url, 'source': o.client, 'e': o.embeded, 'lc':LinkUtils.getLinkCategory(o), 'html_lc':LinkUtils.getLinkCategoryHTML(o), 'n': int(time.mktime(datetime.datetime.now().timetuple()))}}))
			return