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=[]))
示例#2
0
def update_result_search(conn, keyword):
    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.update_row(conn, keyword, search_results, image_search,\
                               news_results, videos_search, torrent_search)
示例#3
0
def update_result_search(conn, keyword):
    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.update_row(conn, keyword, search_results, image_search,\
                               news_results, videos_search, torrent_search)
def webImage(keyword):
    keyword = keyword.upper().lower()
    conn = manage_database.connect_database()
    data_ret = manage_database.search_word(conn, keyword, "images")
    if data_ret == None:
        data_ret = search_image(keyword)
    conn.close()
    if data_ret == None:
        data_ret = []
    return jsonify(keyword=data_ret)
示例#5
0
def webImage(keyword):
    keyword = keyword.upper().lower()
    conn = manage_database.connect_database()
    data_ret = manage_database.search_word(conn, keyword, "images")
    if data_ret == None:
        data_ret = search_image(keyword)
    conn.close()
    if data_ret == None:
        data_ret = []
    return jsonify(keyword=data_ret)
def download(keyword, word_id):
    conn = manage_database.connect_database()
    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, word_id)
    conn.close()
示例#7
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=[]))