Пример #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):
        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)
Пример #3
0
 def GET(self):
     web.header('Content-type', 'text/plain')
     try:
         tag_filter = web.input()['q']
         service = web.input()['service']
         tags = memcache.get("%s|%s" % (tag_filter, service))
         if tags is None:
             se_downloader = StackExchangeDownloader(service)
             tags = se_downloader.get_tags(tag_filter)
             memcache.add("%s|%s" % (tag_filter, service), tags)
         return tags
     except Exception, exception:
         return ""
Пример #4
0
 def GET(self):
     web.header('Content-type', 'application/json')
     try:
         question_id = web.input()['question']
         service = web.input()['service']
         title = memcache.get("%s%s" % (str(question_id), service))
         if title is None:
             se_downloader = StackExchangeDownloader(service)
             title = se_downloader.get_question_title(question_id)
             memcache.add("%s%s" % (str(question_id), service), title, 7200)
         return '{"title":"%s"}' % title.replace('"', '\\"').replace(
             '\\', '\\\\')
     except Exception:
         return '{"title":"%s"}' % NOT_FOUND_ERROR
Пример #5
0
    def GET(self):
        try:
            service = web.input(service=None)['service']
            username = web.input(username=None)['username']
            page = web.input(page=1)['page']
            user_id = web.input(userid=None)['userid']

            if not service:
                return render.favorites()

            if service in StackAuthDownloader.get_supported_services().keys:
                if username:
                    match = re.search('.+\|(\d+)', username)
                    if match:
                        user_id = match.group(1)
                se_downloader = StackExchangeDownloader(service)
                if user_id:
                    users = se_downloader.get_users_by_id(user_id)
                else:
                    users = se_downloader.get_users(username)

                if len(users) > 1:
                    return render.favorites_user_selection(users, service)
                elif len(users) == 1:
                    user_id = users[0]['user_id']
                    result, pagination = se_downloader.get_favorites_questions(
                        user_id, page)
                    return render.favorites_stackexchange(
                        users[0]['display_name'], user_id, result, service,
                        pagination)
                else:
                    return render.favorites(message=NOT_FOUND_ERROR)
            elif service == "delicious":
                try:
                    delicious_downloader = DeliciousDownloader()
                    result = delicious_downloader.get_favorites_questions(
                        username)
                    return render.favorites_delicious(username, result)
                except:
                    return render.favorites(message=NOT_FOUND_ERROR)
            else:
                raise UnsupportedServiceError(service,
                                              UNSUPPORTED_SERVICE_ERROR)
        except (sepy.ApiRequestError, UnsupportedServiceError), exception:
            logging.error(exception)
            return render.oops(exception.message)
Пример #6
0
    def GET(self):

        page = web.input(page=1)['page']
        service = web.input(service=None)['service']
        category = web.input(category=None)['category']
        logout = web.input(logout='false')['logout']

        user_info = None
        associated_sites = None
        associated_sites_keys = None

        user = web.ctx.env.get('webob.adhoc_attrs').get('user')
        if user and user.auth_ids:
            profile_keys = [ndb.Key('UserProfile', p) for p in user.auth_ids]
            profiles = ndb.get_multi(profile_keys)
            user_info = profiles[0].user_info['extra']['raw_info']
            associated_sites = profiles[0].user_info['extra'][
                'associated_sites']
            associated_sites_keys = profiles[0].user_info['extra'][
                'associated_sites_keys']

        if category in ('favorites', 'asked', 'answered') and user_info:
            se_downloader = StackExchangeDownloader(service)
            if category == 'favorites':
                result, pagination = se_downloader.get_favorites_questions(
                    associated_sites[service]['user_id'], page)
            if category == 'asked':
                result, pagination = se_downloader.get_asked_questions(
                    associated_sites[service]['user_id'], page)
            if category == 'answered':
                result, pagination = se_downloader.get_answered_questions(
                    associated_sites[service]['user_id'], page)
            return render.myse_questions(user_info['display_name'],
                                         associated_sites[service]['user_id'],
                                         result, service, pagination, category)

        if logout == 'true' and user_info:
            StackAuthDownloader.invalidate_auth_token(
                (profiles[0].credentials).access_token)
            web.ctx.env.get('webob.adhoc_attrs').get('session').key.delete()
            user.key.delete()
            profiles[0].key.delete()
            web.redirect('/myse')

        return render.myse(user_info, associated_sites, associated_sites_keys)
Пример #7
0
 def GET(self):
     try:
         result = []
         service = web.input(service = None)['service']
         tagged = web.input(tagged = None)['tagged']
         page = web.input(page = 1)['page']
         if not service:
             return render.topvoted()
             
         se_downloader = StackExchangeDownloader(service)
         
         if tagged:
             result, pagination = se_downloader.get_questions_by_tags(tagged, page)
         else:
             result, pagination = se_downloader.get_questions_by_votes(page)
             
         return render.topvoted_tagged(tagged.strip(), result, service, pagination)  
     except (sepy.ApiRequestError, UnsupportedServiceError), exception:
         logging.error(exception)
         return render.oops(exception.message)
Пример #8
0
    def GET(self):
        try:
            render = web.render
            question_id = web.input()['question']
            service = web.input()['service']

            se_downloader = StackExchangeDownloader(service)
            question = se_downloader.get_question_quicklook(question_id)
            if not question:
                return render.oops(NOT_FOUND_ERROR)

            if question.has_key('accepted_answer_id'):
                accepted_answer = se_downloader.get_answer_quicklook(
                    question['accepted_answer_id'])
            else:
                accepted_answer = None

            return render.quicklook(service, question, accepted_answer)
        except (sepy.ApiRequestError, UnsupportedServiceError), exception:
            logging.error(exception)
            return render.oops(exception.message)
Пример #9
0
 def setUp(self):
     self.spdownloader = StackExchangeDownloader('stackoverflow')