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)
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)
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)
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)
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)
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)
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)
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)
from app.config.urls import urls from app.config.constant import UNICORN_MESSAGE_ERROR, NOT_FOUND_ERROR, SERVER_ERROR from app.core.stackprinterdownloader import StackAuthDownloader import app.utility.utils as utils import os if 'app/libauth' not in sys.path: sys.path[0:0] = ['app/libauth'] web.render = render = web.template.render('app/views/', globals = {'date_from':utils.date_from, 'suppify_body':utils.suppify_body, 'commify': web.utils.commify, 'normalize_meta' : utils.normalize_meta, 'urlquote':web.net.urlquote, 'htmlquote':web.net.htmlquote, 'supported_services': StackAuthDownloader.get_supported_services(), 'ERROR_MESSAGE' : UNICORN_MESSAGE_ERROR, }, cache = True) def notfound(): return web.notfound(render.oops(NOT_FOUND_ERROR)) def internalerror(): return web.internalerror(render.oops(SERVER_ERROR)) def redirect_from_appspot(wsgi_app): """Handle redirect to my domain if called from appspot (and not SSL)""" from_server = "stackprinter-hrd.appspot.com" from_server_oldMS = "stackprinter.appspot.com" to_server = "www.stackprinter.com" def redirect_if_needed(env, start_response): if (env["HTTP_HOST"].endswith(from_server) or env["HTTP_HOST"].endswith(from_server_oldMS)) and env["HTTPS"] == "off":
def GET(self): result = {} result['result'] = StackAuthDownloader.renew_auth_token() return render.admin(result)
def GET(self): result = {} result['result'] = StackAuthDownloader.renew_auth_token() return render.admin(result)
import app.utility.utils as utils import os if 'app/libauth' not in sys.path: sys.path[0:0] = ['app/libauth'] web.render = render = web.template.render( 'app/views/', globals={ 'date_from': utils.date_from, 'suppify_body': utils.suppify_body, 'commify': web.utils.commify, 'normalize_meta': utils.normalize_meta, 'urlquote': web.net.urlquote, 'htmlquote': web.net.htmlquote, 'supported_services': StackAuthDownloader.get_supported_services(), 'ERROR_MESSAGE': UNICORN_MESSAGE_ERROR, }, cache=True) def notfound(): return web.notfound(render.oops(NOT_FOUND_ERROR)) def internalerror(): return web.internalerror(render.oops(SERVER_ERROR)) def redirect_from_appspot(wsgi_app): """Handle redirect to my domain if called from appspot (and not SSL)"""