コード例 #1
0
ファイル: articles.py プロジェクト: bojanbabic/Instaright
        def get(self):
		template_variables=[]
                json = LinkUtils.getJsonFromApi('http://www.instaright.com/feed?format=json')
                if json is None:
                        logging.info('default view')
                        self.response.headers["Content-Type"] = "text/xml; charset=utf-8"
		        path = os.path.join(os.path.dirname(__file__), 'templates/sitemap.xml')
		        self.response.out.write(template.render(path, template_variables))
                else:
                        logging.info('dynamic view')
                        links = []
                        for j in json:
                                logging.info('json entry: %s' % j)
                                dd = j['u']['dd']
                                if dd is not None:
                                        links.append((dd, 'hourly'))
                                l = j['u']['l']
                                if l is not None:
                                        links.append((l, 'daily'))
                                lc = j['u']['lc']
                                if lc is not None:
                                        llc = lc.split(',')
                                        for ll in llc:
                                                links.append(('http://www.instaright.com/%s' % ll, 'hourly'))
                        logging.info('list of links: %s ' % len(links))
                        template_variables = { 'links': links }
		        path = os.path.join(os.path.dirname(__file__), 'templates/sitemap_dyn.xml')
		        self.response.out.write(template.render(path, template_variables))
コード例 #2
0
	def get(self, service, method):
                key_name = create_uuid()
        	oauth_code = self.request.get("code")

                oauth_token=''
                self.service = service
        	if service == 'picplz' and oauth_code is not None:
                        logging.info('code %s' % oauth_code)
                        json=LinkUtils.getJsonFromApi('https://picplz.com/oauth2/access_token?client_id=BnYEDMYMrqaKP7DYvQS55meeMHG6s2CA&client_secret=DjZ7DEjzT273tFHvdRPQ49kTA3XJXKpk&grant_type=authorization_code&redirect_uri=http://www.instaright.com/oauth2/picplz/callback&code=%s' % oauth_code)
                	if json is not None:
                                logging.info('picplz response %s' % json)
                        	oauth_token = json['access_token']
                        	logging.info('just got picplz access token %s' % oauth_token)
		self.token = OAuthAccessToken(key_name=key_name, service=service, oauth_token=oauth_token)
        	self.token.put()
                self.set_cookie(key_name)
        	self.redirect('/user/dashboard')
コード例 #3
0
	def html_snapshot(self, condition=None, type=None):
		template_variables=[]
                if condition is None and type is None:
                        url = 'http://www.instaright.com/feed?format=json'
                        title = 'Instaright - SocialBookmarking and recommendation engine'
                        description = 'Instaright provides most productive tools for reading, sharing and discovering online content. Install Instaright addon for Firefox, Chrome or bookmarlet. Discover content using Instaright Realtime Stream or receive message via Instant Messanger of your choice.' 
                elif type is not None and condition is not None:
                        #NOTE: condition contains trailing slash
                        if condition[-1] == '/':
                                condition = condition[:-1]
                        url = 'http://www.instaright.com/%s/%s/feed?format=json' %(type, condition)
                        title = 'Instaright %s articles - %s ' % ( type, condition)
                        description = 'Discover, save and share trending stories from %s' % condition 
                logging.info('feed lookup %s ' % url)
                json = LinkUtils.getJsonFromApi(url)
		if json is None:
			return None
                logging.info('list of links: %s ' % len(json))
                template_variables = { 'links': json, 'condition': condition, 'type': type, 'title': title, 'description': description }
		path = os.path.join(os.path.dirname(__file__), 'templates/html_snapshot.html')
		self.response.out.write(template.render(path, template_variables))
コード例 #4
0
ファイル: link_info.py プロジェクト: bojanbabic/Instaright
 def delicious_data(self, url):
     delicious_api = "http://feeds.delicious.com/v2/json/urlinfo/data?url=%s&type=json" % url
     logging.info("trying to fetch delicious info %s " % delicious_api)
     json = LinkUtils.getJsonFromApi(delicious_api)
     link = Links()
     if json:
         try:
             if not link.title:
                 link.title = json[0]["title"].strip()
             link.categories = db.Text(unicode(simplejson.dumps(json[0]["top_tags"])))
             if link.categories is not None:
                 taskqueue.add(
                     queue_name="category-queue",
                     url="/link/category/delicious",
                     params={"url": url, "categories": link.categories},
                 )
             link.delicious_count = Cast.toInt(json[0]["total_posts"], 0)
             logging.info("delicious count %s" % link.delicious_count)
         except KeyError:
             e0, e1 = sys.exc_info()[0], sys.exc_info()[1]
             logging.info("key error [[%s, %s]] in %s" % (e0, e1, json))
     return link
コード例 #5
0
ファイル: categories.py プロジェクト: bojanbabic/Instaright
        def post(self):
		url=self.request.get('url',None)
                url_hash = LinkUtils.getUrlHash(url)
                if url is None:
                        logging.info('no link in request. skipping')
                        return
                category_api='http://access.alchemyapi.com/calls/url/URLGetCategory?apikey=%s&url=%s&outputMode=json' %(self.alchemy_key, urllib2.quote(url.encode('utf-8')))
                logging.info('trying to fetch shared count info %s' %category_api)
                link=None
                language=None
                category=None

		try:
                	link = Links.gql('WHERE url_hash = :1', url_hash).get()
                        if link is None:
                	        link = Links.gql('WHERE url = :1', url).get()
		except BadValueError:
			logging.info('url property too long')
                if link is None:
                        link = Links()
                else:
                        link.date_updated = datetime.datetime.now().date()
                json = LinkUtils.getJsonFromApi(category_api)
                if json is None:
                        logging.info('alchemy api returned no category.skipping')
                        return
                try:
                    language=json['language']
                    category=json['category']
                    score=Cast.toFloat(json['score'],0)
                    if score is not None and score > 0.5 and category is not None:
                            logging.info('category %s score %s' %(category, score))
                            cats=category.split("_")
                            if cats is None:
                                    logging.info('no categories. exit')
                                    return
                            memcache_key=url_hash+'_category'
                            current_categories=memcache.get(memcache_key)
                            merge_cat=[]
                            if current_categories is not None:
                                    logging.info('merging with existing cats %s' %current_categories)
                                    merge_cat.extend(current_categories)
                                    merge_cat.extend(cats)
                            else: 
                                    merge_cat=cats 
                            model=None 
                            try: 
                                    model=SessionModel.gql('WHERE url_hash = :1 order by date desc', url).get() 
                                    if model is None:
                                        model=SessionModel.gql('WHERE url = :1 order by date desc', url).get()
                            except BadValueError:
                                logging.info('url too long ... %s' %url)
                            if model is None:
                                logging.info('model not defined ... skipping')
                                return

                            linkDetail=Links.gql('WHERE url_hash = :1' , url_hash).get()
                            if linkDetail is None:
                                linkDetail=Links.gql('WHERE url = :1' , url).get()
                            if linkDetail is not None and linkDetail.categories is not None:
                                    logging.info('category found from link details %s' % linkDetail.categories)
                                    delic_cats=eval(linkDetail.categories)
                                    d_cats=[ c for c in  delic_cats ]
                                    merge_cat.extend(d_cats)
                            merge_cat=set(merge_cat)
                            logging.info('caching cats %s for url %s' %(merge_cat, url))
                            memcache.set(memcache_key, list(set(merge_cat))[:4])

                            for c in merge_cat:
                                taskqueue.add(queue_name='message-broadcast-queue', url='/category/stream', params={'category':c, 'url': url_hash})
                                existingLinkCat = LinkCategory.gql('WHERE url_hash = :1 and category = :2', url_hash, c).get()
                                if existingLinkCat is None:
                                        existingLinkCat = LinkCategory.gql('WHERE url = :1 and category = :2', url, c).get()
                                if existingLinkCat is not None:
                                        existingLinkCat.updated=datetime.datetime.now()
                                        if existingLinkCat.url_hash is None:
                                                existingLinkCat.url_hash = url_hash
                                        existingLinkCat.put()
                                        logging.info('updated exisitng url(%s) category(%s) update time %s' % (url, c, existingLinkCat.updated))
                                else:
                                        logging.info('new pair: url%s) category(%s) ' % (url, c))
                                        linkCategory=LinkCategory()
                                        linkCategory.url=url
                                        linkCategory.url_hash = url_hash
                                        linkCategory.category=c
                                        if model is not None:
                                                linkCategory.model_details=model.key()
                                        linkCategory.put()

                    if language is not None:
                            link.language = language
                    link.url=url
                    link.url_hash=url_hash
                    link.put()
                except KeyError:
                    e0, e1 = sys.exc_info()[0],sys.exc_info()[1]
                    logging.info('key error [[%s, %s]] in %s' %(e0, e1, json))