def my_form_post():
    keyword = request.form['text']
    keyword = keyword.upper().lower()
    data_type = get_id_type(request.form['platform'])
    resultSearch = []
    start_download = False
    word_id = 0

    print "adresse ip : ", request.remote_addr
    conn = manage_database.connect_database()
    manage_database.add_connection_user(conn, request.remote_addr)
    if keyword == None or keyword == "":
        return (render_template("index.html", type=data_type, dataResults=[]))
        
    data_ret = manage_database.search_word(conn, keyword, request.form['platform'])

    if data_ret == None:
        start_download = True
        cursor = conn.cursor()
        cursor.execute('''INSERT INTO keyword (word, nb) VALUES(?, ?)''', (keyword, 1,))
        word_id = cursor.lastrowid
        conn.commit()
        """
        search_results = search(keyword)
        image_search = search_image(keyword)
        news_results = searchNews(keyword)
        videos_search = search_video(keyword)
        torrent_search = search_torrent(keyword)
        manage_database.fill_new_entry(conn, keyword, search_results, image_search, \
                                       news_results, videos_search, torrent_search)
        """
    else:
        resultSearch = data_ret

    thread_download = threading.Thread(target=optimise_request.download, args=(keyword, word_id))
    if request.form['platform'] == "search":
        if data_ret == None:
            resultSearch = search(keyword)
    elif request.form['platform'] == "images":
        if data_ret == None:
            resultSearch = search_image(keyword)
    elif request.form['platform'] == "news":
        if data_ret == None:
            resultSearch = searchNews(keyword)
    elif request.form['platform'] == "videos":
        if data_ret == None:
            resultSearch = search_video(keyword)
    elif request.form['platform'] == "torrent":
        if data_ret == None:
            resultSearch = search_torrent(keyword)

    if start_download == True:
        thread_download.start()

    conn.close()

    if resultSearch != None:
        return (render_template("index.html", type=data_type, dataResults=resultSearch))
    return (render_template("index.html", type=data_type, dataResults=[]))
def webSearch(keyword):
    keyword = keyword.upper().lower()
    conn = manage_database.connect_database()
    data_ret = manage_database.search_word(conn, keyword, "search")
    if data_ret == None:
        data_ret = search(keyword)
    conn.close()
    if data_ret == None:
        data_ret = []
    return jsonify(keyword=data_ret)
Esempio n. 3
0
def webSearch(keyword):
    keyword = keyword.upper().lower()
    conn = manage_database.connect_database()
    data_ret = manage_database.search_word(conn, keyword, "search")
    if data_ret == None:
        data_ret = search(keyword)
    conn.close()
    if data_ret == None:
        data_ret = []
    return jsonify(keyword=data_ret)
Esempio n. 4
0
def my_form_post():
    keyword = request.form['text']
    keyword = keyword.upper().lower()
    data_type = get_id_type(request.form['platform'])
    resultSearch = []
    start_download = False
    word_id = 0

    print "adresse ip : ", request.remote_addr
    conn = manage_database.connect_database()
    manage_database.add_connection_user(conn, request.remote_addr)
    if keyword == None or keyword == "":
        return (render_template("index.html", type=data_type, dataResults=[]))

    data_ret = manage_database.search_word(conn, keyword,
                                           request.form['platform'])

    if data_ret == None:
        start_download = True
        cursor = conn.cursor()
        cursor.execute('''INSERT INTO keyword (word, nb) VALUES(?, ?)''', (
            keyword,
            1,
        ))
        word_id = cursor.lastrowid
        conn.commit()
        """
        search_results = search(keyword)
        image_search = search_image(keyword)
        news_results = searchNews(keyword)
        videos_search = search_video(keyword)
        torrent_search = search_torrent(keyword)
        manage_database.fill_new_entry(conn, keyword, search_results, image_search, \
                                       news_results, videos_search, torrent_search)
        """
    else:
        resultSearch = data_ret

    thread_download = threading.Thread(target=optimise_request.download,
                                       args=(keyword, word_id))
    if request.form['platform'] == "search":
        if data_ret == None:
            resultSearch = search(keyword)
    elif request.form['platform'] == "images":
        if data_ret == None:
            resultSearch = search_image(keyword)
    elif request.form['platform'] == "news":
        if data_ret == None:
            resultSearch = searchNews(keyword)
    elif request.form['platform'] == "videos":
        if data_ret == None:
            resultSearch = search_video(keyword)
    elif request.form['platform'] == "torrent":
        if data_ret == None:
            resultSearch = search_torrent(keyword)

    if start_download == True:
        thread_download.start()

    conn.close()

    if resultSearch != None:
        return (render_template("index.html",
                                type=data_type,
                                dataResults=resultSearch))
    return (render_template("index.html", type=data_type, dataResults=[]))