Exemplo n.º 1
0
def index(request):
    #print os.getcwd()
    htmlpath = 'server/templates/server/result.html'
    if not os.path.exists(htmlpath):
        answerrot.write_html_file(htmlpath, '')

    if request.method == 'POST':
        return render(request, 'server/index.html', {
            "result": "error",
            "time": ""
        })
    if not request.GET.has_key('submit'):
        return render(request, 'server/index.html', {"result": ""})
    atype = '1'
    if not request.GET.has_key('type'):
        #return   render(request, 'server/index.html', {"result": "参数错误", "time": ""})
        pass
    else:
        atype = request.GET['type']
    search = '1'
    if request.GET.has_key('type'):
        search = request.GET['search']
    delno = ""
    if request.GET.has_key('delno'):
        delno = request.GET['delno']
    addans = ""
    if request.GET.has_key('addans'):
        addans = request.GET['addans']

    start = time.time()
    imgpath = os.path.join(os.getcwd(), 'server\\img\\1.jpg')

    e = adb.get_pic(imgpath)
    if e != True:
        #return  render(reverse('server/config.html', {"result": "", "msg": e + ", Check device number"}))
        return HttpResponseRedirect('/config/?msg=' + e +
                                    ", Check device number")

    ci = adb.get_config("client_id")
    if ci == "":
        return HttpResponseRedirect('/config/?msg=Config client_id')
    ck = adb.get_config("client_secret")
    if ck == "":
        return HttpResponseRedirect('/config/?msg=Config client_secret')

    sx = adb.get_config("sx")
    if sx == "":
        return HttpResponseRedirect('/config/?msg=Config screen width')
    sy = adb.get_config("sy")
    if sy == "":
        return HttpResponseRedirect('/config/?msg=Config screen height')

    res = answerrot.ocr(imgpath, htmlpath, int(atype), int(search), delno,
                        addans, ci, ck, int(sx), int(sy))

    return render(request, 'server/index.html', {
        "question": res[0],
        "answer": res[1],
        "time": time.time() - start
    })
Exemplo n.º 2
0
def index(request):
    #print os.getcwd()
    htmlpath = 'server/templates/server/result.html'
    if not os.path.exists(htmlpath):
        answerrot.write_html_file(htmlpath, '')

    if request.method == 'POST':
        return  render(request, 'server/index.html', {"result": "error", "time": ""})
    if not request.GET.has_key('submit'):
        return  render(request, 'server/index.html', {"result": ""})
    atype = '1'
    if not request.GET.has_key('type'):
        #return   render(request, 'server/index.html', {"result": "参数错误", "time": ""})
        pass
    else:
        atype = request.GET['type']
    search = '1'
    if request.GET.has_key('type'):
        search = request.GET['search']
        
    start = time.time()
    imgpath = os.path.join(os.getcwd(), 'server\\img\\1.jpg')
    
    e  = adb.get_pic(imgpath)
    if e != True:
        #return  render(reverse('server/config.html', {"result": "", "msg": e + ", Check device number"}))
        return HttpResponseRedirect('/config/?msg='+e + ", Check device number")  

    ci = adb.get_config("client_id")
    if ci == "":
        return HttpResponseRedirect('/config/?msg=Config client_id')  
    ck = adb.get_config("client_secret")
    if ck == "":
        return HttpResponseRedirect('/config/?msg=Config client_secret')

    sx = adb.get_config("sx")
    if sx == "":
        return HttpResponseRedirect('/config/?msg=Config screen width')  
    sy = adb.get_config("sy")
    if sy == "":
        return HttpResponseRedirect('/config/?msg=Config screen height')  

    res = answerrot.ocr(imgpath, htmlpath, int(atype), int(search), ci, ck, int(sx), int(sy))

    return  render(request, 'server/index.html', {"result": res, "time": time.time()-start})
Exemplo n.º 3
0
def search(request):
    htmlpath = 'server/templates/server/result.html'
    if not os.path.exists(htmlpath):
        answerrot.write_html_file(htmlpath, '')

    start = time.time()
    if request.method != 'POST':
        return render(request, 'server/index.html', {
            "question": "MUST use POST method!",
            "time": ""
        })

    atype = '1'
    if request.GET.has_key('type'):
        atype = request.GET['type']
    search = '1'
    if request.GET.has_key('type'):
        search = request.GET['search']

    imgpath = os.path.join(os.getcwd(), 'server\\img\\1.jpg')

    def write_file(path, data):
        f = file(path, 'wb')
        f.write(data)
        f.close()

    # ajax
    # for va in request.POST:
    #     print type(va)
    #     lens = len(va)
    #     lenx = lens - (lens % 4 if lens % 4 else 4)
    #     try:
    #         write_file(imgpath, base64.b64decode(urllib.unquote(va)))
    #     except:
    #         pass
    #     break
    if not request.POST.has_key('data'):
        return render(request, 'server/index.html', {
            "question": "No jpg data!",
            "time": ""
        })
    data = request.POST['data']
    try:
        write_file(imgpath, base64.b64decode(urllib.unquote(data)))
    except:
        pass

    ci = adb.get_config("client_id")
    if ci == "":
        return HttpResponseRedirect('/config/?msg=Config client_id')
    ck = adb.get_config("client_secret")
    if ck == "":
        return HttpResponseRedirect('/config/?msg=Config client_secret')

    # sx = adb.get_config("sx")
    # if sx == "":
    #     return HttpResponseRedirect('/config/?msg=Config screen width')
    # sy = adb.get_config("sy")
    # if sy == "":
    #     return HttpResponseRedirect('/config/?msg=Config screen height')

    res = answerrot.ocr(imgpath, htmlpath, int(atype), int(search), ci, ck, 0,
                        0, False)

    return render(request, 'server/index.html', {
        "question": res[0],
        "answer": res[1],
        "time": time.time() - start
    })