Пример #1
0
def index():
    results = []
    error = None
    if request.method == "POST":
        dbconnection = DBConnection()
        conn = dbconnection.mongodb_conn()

        if request.form['text-box'] == '':
            return '', 204

        URL = request.form['text-box']
        URL = URL.replace(" ", "")

        dataSplited = list()

        if (URL.endswith('.txt')):
            # parseo los datos y los subo
            scrapper = Scrapper(URL)
            scrapper.get_data()
            scrapper.parse_data()

            print scrapper.dictOfWords

            if conn is not None:
                for key in scrapper.dictOfWords.keys():
                    dbconnection.save_in_database(key,
                                                  scrapper.dictOfWords[key])

            print "posting data"

        words = list()

        # recojo los datos y los muestro
        if conn is not None:
            words = dbconnection.get_all_data_from_database()
            for word in words:
                results.append(word)
        else:
            error = "Database is down."
            print error

    return render_template('index.html', results=results, error=error)