def insert_new_link(url, title=None, log=False): """Inserts a new LinkEnt into the datastore. If no title is provided, get_title() will be called to find it. Returns the link score. """ if not title: title = get_title(url) score = get_score(url) if log: logging.info('Inserting link %s with score %d' % \ (url, score[0])) le = LinkEnt(title=title, url=url, score=score[0]) le.put() return score
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)