Пример #1
0
 def GET(self):
     
     result = {}
     service_parameter = web.input(service = None)['service']
     question_id_parameter = web.input(question_id = None)['question_id']
     sort_parameter = web.input(sort = 'week')['sort']
     pagesize_parameter = web.input(pagesize = 30)['pagesize']
     try:
         if service_parameter:
             se_downloader = StackExchangeDownloader(service_parameter)
             if question_id_parameter:
                 se_downloader.get_post(question_id_parameter, False)
             else:
                 questions = se_downloader.get_questions_by_hotness(pagesize = pagesize_parameter, 
                                                                    sort = sort_parameter)
                 for question in questions:
                     question_id = int(question['question_id'])
                     score = int(question['score'])
                     if score > VOTES_ENTRY_LEVEL:
                         taskqueue.add(url='/admin/topquestionsretriever?service=%s&question_id=%s&sort=%s' % \
                                       (service_parameter, question_id, sort_parameter) , 
                                       method = 'GET', 
                                       queue_name = 'retriever')
         else:
             supported_services = StackAuthDownloader.get_supported_services()
             for service in supported_services.keys:
                 if not service.startswith('meta.'):
                     taskqueue.add(url='/admin/topquestionsretriever?service=%s&sort=%s' % \
                                   (service, sort_parameter), 
                                   method = 'GET', 
                                   queue_name = 'retriever')
     except Exception:
         logging.exception("Exception handling TopQuestionRetriever")
     result['result'] = True
     return render.admin(result)
Пример #2
0
 def GET(self):
     
     result = {}
     service_parameter = web.input(service = None)['service']
     question_id_parameter = web.input(question_id = None)['question_id']
     sort_parameter = web.input(sort = 'week')['sort']
     pagesize_parameter = web.input(pagesize = 30)['pagesize']
     try:
         if service_parameter:
             se_downloader = StackExchangeDownloader(service_parameter)
             if question_id_parameter:
                 se_downloader.get_post(question_id_parameter, False)
             else:
                 questions = se_downloader.get_questions_by_hotness(pagesize = pagesize_parameter, 
                                                                    sort = sort_parameter)
                 for question in questions:
                     question_id = int(question['question_id'])
                     score = int(question['score'])
                     if score > VOTES_ENTRY_LEVEL:
                         taskqueue.add(url='/admin/topquestionsretriever?service=%s&question_id=%s&sort=%s' % \
                                       (service_parameter, question_id, sort_parameter) , 
                                       method = 'GET', 
                                       queue_name = 'retriever')
         else:
             supported_services = StackAuthDownloader.get_supported_services()
             for service in supported_services.keys:
                 if not service.startswith('meta.'):
                     taskqueue.add(url='/admin/topquestionsretriever?service=%s&sort=%s' % \
                                   (service, sort_parameter), 
                                   method = 'GET', 
                                   queue_name = 'retriever')
     except Exception:
         logging.exception("Exception handling TopQuestionRetriever")
     result['result'] = True
     return render.admin(result)
Пример #3
0
    def GET(self):
        try:
            #return render.oops("..OFFLINE FOR MAINTENANCE..")
            question_id = web.input(question=None)['question']
            service = web.input(service=None)['service']
            pretty_links = web.input(prettylinks='true')['prettylinks']
            printer = web.input(printer='true')['printer']
            link_to_home = web.input(linktohome='true')['linktohome']
            pretty_print = web.input(prettyprint='true')['prettyprint']
            comments = web.input(comments='true')['comments']
            format = web.input(
                format='HTML')['format']  #For future implementations
            answer_id = web.input(answer=None)['answer']
            hide_question = web.input(hidequestion='true' if (
                answer_id is not None) else 'false')['hidequestion']
            #Check for malformed request
            if not service or not question_id or not question_id.isdigit() or (
                    answer_id and not answer_id.isdigit()):
                return Index().GET()

            #Meta normalization
            service = utils.normalize_meta(service)

            #Check for static questions
            if "%s_%s" % (service, question_id) in urls.static_questions:
                deferred.defer(worker.deferred_static_counters, question_id,
                               service)
                return web.redirect(
                    urls.static_questions["%s_%s" % (service, question_id)])

            se_downloader = StackExchangeDownloader(service)

            #Everything that comes outside the stackprinter homepage, stackoverflow and stackexchange is now heavily cached

            bypass_cache = False
            referrer = os.environ.get("HTTP_REFERER")
            if referrer:
                try:
                    referrer_key = re.match('^(http|https)://(.*).com',
                                            referrer).group(2)
                    if referrer_key in StackAuthDownloader.get_supported_services(
                    ).keys or referrer in ('http://www.stackprinter.com/',
                                           'http://stackprinter.appspot.com/'):
                        bypass_cache = True
                except:
                    pass

            post = se_downloader.get_post(question_id, bypass_cache)

            if post is None:
                return render.oops(NOT_FOUND_ERROR)

            return render.export(service, post, pretty_links == 'true',
                                 printer == 'true', link_to_home == 'true',
                                 pretty_print == 'true', comments == 'true',
                                 answer_id, hide_question == 'true')
        except (sepy.ApiRequestError, UnsupportedServiceError), exception:
            logging.error(exception)
            return render.oops(exception.message)
Пример #4
0
    def GET(self):
        try:
            #return render.oops("..OFFLINE FOR MAINTENANCE..")
            question_id = web.input(question = None)['question']
            service = web.input(service = None)['service']
            pretty_links =  web.input(prettylinks = 'true')['prettylinks']
            printer =  web.input(printer = 'true')['printer']
            link_to_home = web.input(linktohome = 'true')['linktohome']
            pretty_print = web.input(prettyprint = 'true')['prettyprint']
            comments = web.input(comments = 'true')['comments']
            format = web.input(format = 'HTML')['format'] #For future implementations
            answer_id = web.input(answer = None)['answer']
            font_family = web.input(font_family = DEFAULT_FONT_FAMILY)['font_family']
            hide_question = web.input(hidequestion = 'true' if (answer_id is not None) else 'false' )['hidequestion']
            #Check for malformed request
            if not service or not question_id or not question_id.isdigit() or (answer_id and not answer_id.isdigit()):
                return Index().GET()
            
            #Normalize font-family
            if not font_family.replace(" ","").isalpha():
                font_family = DEFAULT_FONT_FAMILY
            
            #Meta normalization
            service = utils.normalize_meta(service)
            
            #Check for static questions
            if "%s_%s" % (service,question_id) in urls.static_questions:
                deferred.defer(worker.deferred_static_counters, question_id, service)
                return web.redirect(urls.static_questions["%s_%s" % (service,question_id)])
            
            se_downloader = StackExchangeDownloader(service)
            
            #Everything that comes outside the stackprinter homepage, stackoverflow and stackexchange is now heavily cached
            
            bypass_cache = False
            referrer = os.environ.get("HTTP_REFERER")
            if referrer:
                try:
                    referrer_key = re.match('^(http|https)://(.*).com',referrer).group(2)
                    if referrer_key in StackAuthDownloader.get_supported_services().keys or referrer in ('http://www.stackprinter.com/','http://stackprinter.appspot.com/'):
                        bypass_cache = True
                except:
                    pass

            post = se_downloader.get_post(question_id, bypass_cache)
            
            if post is None:
                return render.oops(NOT_FOUND_ERROR)
                
            return render.export(service, post, pretty_links == 'true', printer == 'true', link_to_home == 'true', pretty_print == 'true', comments == 'true', answer_id, hide_question == 'true', font_family )
        except (sepy.ApiRequestError, UnsupportedServiceError), exception:
            logging.error(exception)
            return render.oops(exception.message)