Example #1
0
def previous(id):
    starting = int(id.split('_')[1])
    query = request.args.get('q')
    if query is None or query == "":
        query = ""
        data = db.get_prev(starting)
    else:
        tag_list = ip.parser(query)
        data = db.tagged_get_prev(starting, tag_list)
    if not data:
        code = 404
        data = ""
    else:
        code = 200
        data = data[6] + str(data[7])

    return Response(data + "?q={}".format(query), status=code)
Example #2
0
def search():
    page = request.args.get('page', default=1, type=int)
    query = request.args.get('q', default='', type=str)
    db_search_list = ip.parser(query)
    try:
        results, total = db.search(db_search_list['search'],
                                   db_search_list['remove'],
                                   page=page - 1)
        results = [DBImage(x) for x in results]
    except (IndexError, KeyError):
        pass
    return render_template('results.html',
                           search=query,
                           page=page,
                           total_images=total,
                           results=results,
                           settings_file=settings_file,
                           str=str,
                           ceil=math.ceil,
                           max=max)
Example #3
0
def api_search():
    page = request.args.get('page', default=1, type=int)
    query = request.args.get('q', default='', type=str)
    db_search_list = ip.parser(query)
    try:
        results, total = db.search(db_search_list['search'],
                                   db_search_list['remove'],
                                   page=page - 1)
    except (IndexError, KeyError):
        pass
    del total
    result = {}
    k = 0
    for _ in results:
        fname = {'filename': _[0]}
        tags = {'tags': _[1].split(",,")[1:-2]}
        height = {'height': _[2]}
        width = {'widht': _[3]}
        ratio = {'ratio': _[4]}
        source_link = {'source_link': _[5]}
        prefix = {'prefix': _[6]}
        thumbnail = {
            'thumb':
            "//" + request.host + "/thumbnail/" + prefix['prefix'] +
            fname['filename']
        }
        full = {
            'full':
            "//" + request.host + "/raw/" + prefix['prefix'] +
            fname['filename']
        }
        __ = dict(fname, **tags, **height, **width, **ratio, **source_link,
                  **prefix, **thumbnail)
        __.update(full)
        result[k] = __
        k += 1
    result = json.dumps(result)
    return Response(result, mimetype="application/json")
Example #4
0
def main_cycle():
    inp = input("\nDB> ")
    inp = inp.lower()
    if inp == "get images":
        update_db()
    elif inp == "get images --force":
        update_db()
    elif inp == "total":
        db.total_found()
    elif "count" in inp:
        counttag = inp.strip().split("count")[1].strip()
        db.count_tag(counttag)
    elif inp == '':
        main_cycle()
    elif inp == 'quit' or inp == 'exit':
        os._exit(0)
    elif inp == "help":
        show_help(1)
    else:
        query = ip.parser(inp)
        results, total = db.search(query['search'], query['remove'])
        query_cycle(total[0], inp)
    main_cycle()
Example #5
0
def tagged_rand(tags):
    tags_list = ip.parser(tags)
    result = db.tagged_random(tags_list)
    return redirect("/image/" + result[-2] + str(result[-1]) + "?q=" + tags)
Example #6
0
def query_cycle(total, query):
    if total == 0:
        print("Nothing found.")
        main_cycle()
    else:
        pages = int(total / settings_file.showing_imgs)+1
        print("Found {} pages".format(pages))
        while True:
            inp = input("\nSearch@DB> ")
            inp = inp.lower()
            if inp == "back":
                break

            elif inp.isnumeric():
                if int(inp) > pages:
                    print("No such page")
                l_s = ip.parser(query)['search']
                l_r = ip.parser(query)['remove']
                results, total = db.search(l_s, l_r, int(inp)-1)
                page_dict = {}
                for i in range(len(results)):
                    page_dict[i+1] = results[i]
                for i in page_dict:
                    print("({}) => {}".format(i, page_dict[i][1].split(",,")[:settings_file.showing_tags]))

            elif "show" in inp:
                inp = inp.split("show")[1]
                try:
                    file_name = str(page_dict[int(inp.strip())][6]) + str(page_dict[int(inp.strip())][0])
                except IndexError:
                    print("Usage: show <id>")
                try:
                    webbrowser.open(os.path.dirname(os.path.realpath(
                        __file__)) + "/" + str(settings_file.images_path.replace('.','') + file_name))
                except FileNotFoundError:
                    print("File doesn't exist.")

            elif "export" in inp:
                inp = inp.split("export")[1]
                file_name = str(page_dict[int(inp.strip())][6]) + str(page_dict[int(inp.strip())][0])
                try:
                    shutil.copy(os.path.dirname(os.path.realpath(__file__)) + str(settings_file.images_path +
                                                                                  file_name),
                                os.path.dirname(os.path.realpath(__file__)) + str(settings_file.export_path +
                                                                                  file_name))
                except FileNotFoundError:
                    os.mkdir(settings_file.export_path)
                else:
                    pass

            elif inp == '':
                pass

            elif inp == "help":
                show_help(2)

            elif inp == 'quit' or inp == 'exit':
                os._exit(0)

            else:
                query = ip.parser(inp)
                results, total = db.search(query['search'], query['remove'])
                query_cycle(total[0], inp)