示例#1
0
文件: scores.py 项目: rinze/rank-es
def get_score(url):
    """Returns the global score"""

    # Fix the URL and quote it
    try:
        url = urllib2.quote(fix_url(url))
    except:
        # This happens once in a while
        logging.critical('Error while quoting url %s' % url)
        url = fix_url(url)

    # Get partial and global scores
    fb = get_fb_score(url)
    tw = get_tw_score(url)   
    scores = fb, tw
    return fb+tw, scores
示例#2
0
文件: rank_es.py 项目: rinze/rank-es
    def get(self):       

        # Get url if provided
        url = self.request.get('url')
        via = self.request.get('via')
        
        
        if url and url != '':
            # Insert new link into database and regenerate front page
            # Check if link already in database (current and old)
            url = fix_url(url)
            cor_url = correct_url(url)
            if cor_url and not url_in_db(url):
                title = get_title(url)
                # Insert link into database
                score, (_, _) = insert_new_link(url, title)
                logging.info('New link inserted from front page: %s (%d)' %
                              (url, score))

                # Generate main page
                if score > memcache.get('minscore'):    #@UndefinedVariable                    
                    generate_main_page() 
                    logging.info('Front page updated')
                else:
                    logging.info('Front page not updated')           
                    
                # Feedback
                self.redirect('/submitted?via=%s&url=%s&score=%s' % 
                              (via, url, str(score)))
                
            else:
                self.redirect('/submittederror?via=%s&url=%s' % 
                              (via, url))
                
        main_page = memcache.get('index')   #@UndefinedVariable
        if not main_page:
            main_page = generate_main_page()
        self.response.out.write(main_page)