コード例 #1
0
ファイル: dictionary_server.py プロジェクト: bsloan666/urban
def index():

    random = False
    unsafe = False
    animated = False
    base = "http://%s/"%request.environ['HTTP_HOST']
    curr = base
    animchecked = ""
    unsfchecked = ""
    randchecked = ""
    if request.args.get('a') is not None:
        animated = True
        animchecked = "checked"
    if request.args.get('u') is not None:
        unsafe = True
        unsfchecked = "checked"
    if request.args.get('r') is not None:
        random = True
        randchecked = "checked"

    redirect_to_url = False
    if request.args.get('adj') and request.args.get('noun'):
        adj = escape(request.args.get('adj'))
        noun = escape(request.args.get('noun'))
        if request.args.get('imgurl'):
            imgurl = escape(request.args.get('imgurl'))
            imgenc = b64encode(imgurl)
        elif request.args.get('imgenc'):
            imgenc = request.args.get('imgenc')
            imgurl = escape(b64decode(imgenc))
        redirect_to_url = True
    else:
        adj,alt_adj,noun,alt_noun = generate.random_phrase_2()
        imgroot = '%s %s'%(adj,noun)
        if random:
            imgroot = '%s %s'%(alt_adj,alt_noun)
        imgurl = find_image(imgroot, animated, unsafe)
        imgenc = b64encode(imgurl)

    current_context = {'adj': adj, 'noun': noun, 'img': imgurl}
    hashed_context = protect_context(current_context)
    url_context = {'hash': hashed_context}
    url_context.update(current_context)

    root = '%s %s'%(adj,noun)
    info_data = b64encode(json.dumps(url_context))
    thisview = "{0}://{1}/{2}".format(
        request.environ['wsgi.url_scheme'],
        request.environ['HTTP_HOST'],
        info_data
    )

    if redirect_to_url:
        return redirect('/{0}'.format(info_data))

    quote=urllib2.quote(colon_to_pct(thisview))

    return render_template('index.html.tpl', text=root, img=imgurl,
        permalink=thisview, current_url=curr, baseurl=base, quotelink=quote,
        animchecked=animchecked, unsfchecked=unsfchecked, randchecked=randchecked)
コード例 #2
0
def index():

    random = False
    unsafe = False
    animated = False
    base = "http://%s/" % request.environ['HTTP_HOST']
    curr = base
    animchecked = ""
    unsfchecked = ""
    randchecked = ""
    if request.args.get('a') is not None:
        animated = True
        animchecked = "checked"
    if request.args.get('u') is not None:
        unsafe = True
        unsfchecked = "checked"
    if request.args.get('r') is not None:
        random = True
        randchecked = "checked"

    if request.args.get('adj') and request.args.get('noun'):
        adj = escape(request.args.get('adj'))
        noun = escape(request.args.get('noun'))
        if request.args.get('imgurl'):
            imgurl = escape(request.args.get('imgurl'))
            imgenc = b64encode(imgurl)
        elif request.args.get('imgenc'):
            imgenc = request.args.get('imgenc')
            imgurl = escape(b64decode(imgenc))
    else:
        adj, alt_adj, noun, alt_noun = generate.random_phrase_2()
        imgroot = '%s %s' % (adj, noun)
        if random:
            imgroot = '%s %s' % (alt_adj, alt_noun)
        imgurl = find_image(imgroot, animated, unsafe)
        imgenc = b64encode(imgurl)

    root = '%s %s' % (adj, noun)
    thisview = "http://%s/?adj=%s&noun=%s&imgenc=%s" % (
        request.environ['HTTP_HOST'], space_to_plus(adj), space_to_plus(noun),
        imgenc)

    quote = urllib2.quote(colon_to_pct(thisview))

    return render_template('index.html.tpl',
                           text=root,
                           img=imgurl,
                           permalink=thisview,
                           current_url=curr,
                           baseurl=base,
                           quotelink=quote,
                           animchecked=animchecked,
                           unsfchecked=unsfchecked,
                           randchecked=randchecked)
コード例 #3
0
ファイル: dictionary_server.py プロジェクト: brandonvfx/urban
def index():

    random = False
    unsafe = False
    animated = False
    base = "http://%s/"%request.environ['HTTP_HOST']
    curr = base
    animchecked = ""
    unsfchecked = ""
    randchecked = ""
    if request.args.get('a') is not None:
        animated = True
        animchecked = "checked"
    if request.args.get('u') is not None:
        unsafe = True
        unsfchecked = "checked"
    if request.args.get('r') is not None:
        random = True
        randchecked = "checked"

    if request.args.get('adj') and request.args.get('noun'):
        adj = escape(request.args.get('adj'))
        noun = escape(request.args.get('noun'))
        if request.args.get('imgurl'):
            imgurl = escape(request.args.get('imgurl'))
            imgenc = b64encode(imgurl) 
        elif request.args.get('imgenc'):
            imgenc = request.args.get('imgenc')
            imgurl = escape(b64decode(imgenc))
    else:
        adj,alt_adj,noun,alt_noun = generate.random_phrase_2()
        imgroot = '%s %s'%(adj,noun)
        if random:
            imgroot = '%s %s'%(alt_adj,alt_noun)
        imgurl = find_image(imgroot, animated, unsafe)
        imgenc = b64encode(imgurl)

    root = '%s %s'%(adj,noun)
    thisview = "http://%s/?adj=%s&noun=%s&imgenc=%s"%(request.environ['HTTP_HOST'],
        space_to_plus(adj),space_to_plus(noun), imgenc)

    quote=urllib2.quote(colon_to_pct(thisview))

    return render_template('index.html.tpl', text=root, img=imgurl,
        permalink=thisview, current_url=curr, baseurl=base, quotelink=quote,
        animchecked=animchecked, unsfchecked=unsfchecked, randchecked=randchecked)
コード例 #4
0
ファイル: dictionary_server.py プロジェクト: bsloan666/urban
def index():
    """
    main entrypoint
    """
    random = False
    unsafe = False
    animated = False
    base = "http://%s/"%request.environ['HTTP_HOST']
    curr = base
    animchecked = ""
    unsfchecked = ""
    randchecked = ""
    if request.args.get('a') is not None:
        animated = True
        animchecked = "checked"
    if request.args.get('u') is not None:
        unsafe = True
        unsfchecked = "checked"
    if request.args.get('r') is not None:
        random = True
        randchecked = "checked"

    redirect_to_url = False
    if request.args.get('adj') and request.args.get('noun'):
        adj = escape(request.args.get('adj'))
        noun = escape(request.args.get('noun'))
        if request.args.get('imgurl'):
            imgurl = escape(request.args.get('imgurl'))
            imgenc = b64encode(imgurl)
        elif request.args.get('imgenc'):
            imgenc = request.args.get('imgenc')
            imgurl = escape(b64decode(imgenc))
        redirect_to_url = True
    else:
        adj, alt_adj, noun, alt_noun = generate.random_phrase_2()
        imgroot = '%s %s'%(adj, noun)
        if random:
            imgroot = '%s %s'%(alt_adj, alt_noun)
        imgurl = find_image(imgroot, animated, unsafe)
        print("IMAGE URL",imgurl)
        imgenc = b64encode(bytes(imgurl, 'utf-8'))

    current_context = {'adj':adj, 'noun':noun, 'img':imgurl}
    hashed_context = protect_context(current_context)
    url_context = {'hash':hashed_context}
    url_context.update(current_context)

    root = '%s %s'%(adj, noun)
    info_data = b64encode(bytes(json.dumps(url_context), 'utf-8'))
    thisview = "{0}://{1}/{2}".format(
        request.environ['wsgi.url_scheme'],
        request.environ['HTTP_HOST'],
        info_data
    )

    if redirect_to_url:
        return redirect('/{0}'.format(info_data))

    quote = urllib.parse.quote(colon_to_pct(thisview))

    return render_template('index.html.tpl', text=root, img=imgurl,
                           permalink=thisview, current_url=curr, baseurl=base, quotelink=quote,
                           animchecked=animchecked, unsfchecked=unsfchecked,
                           randchecked=randchecked)