コード例 #1
0
def home():
    form = MainForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            if not verify(form.url_field.data):
                flash('Please enter a valid YouTube URL', 'danger')

            format_display = dict(FormatChoices).get(form.output_format.data)

            if format_display == 'Video':
                result = downloadVideo(form.url_field.data)
                print(result)
                if result == "-1" or result == "-2":
                    flash('An unexpected error has occured. Please try again',
                          'danger')
                else:
                    flash('File successfully converted', 'success')
                    form.url_field.data = ""
                    return redirect('/downloadfile/' + result)

            elif format_display == "Audio":
                result = downloadAudio(form.url_field.data)

                if result == "-1" or result == "-2":
                    flash('An unexpected error has occured. Please try again',
                          'danger')
                else:
                    flash('File successfully converted', 'success')
                    return redirect('/downloadfile/' + result)

    return render_template('index.html', form=form)
コード例 #2
0
def index():
    if 'username' in session:
        mform_2 = MainForm()
        if mform_2.validate_on_submit() :
            return render_template('main.html', mform = mform_2, username = session['username'], search = search_games(mform_2))

        return render_template('main.html', mform = mform_2, username = session['username'], search=get_all())

    return render_template('index.html')
コード例 #3
0
ファイル: main.py プロジェクト: kevingtz/AI_class
def index():
    form = MainForm()
    if form.validate_on_submit():
        c_i = form.number_of_cities.data
        c_o = form.number_of_colors.data
        n_r = form.number_of_relations.data
        t_r = form.relations.data
        results = process_the_info(c_i, c_o, n_r, t_r)
        return redirect(url_for('result', results=results))

    return render_template('index.html', form=form)
コード例 #4
0
def hello_world():
    today = datetime.now().strftime('%A %d %b %Y')
    global dollarRates
    form = MainForm()
    if form.validate_on_submit():
        if form.firstCurr.data == form.secondCurr.data:
            return redirect('/')
        else:
            uri = '/search?in=' + form.firstCurr.data + '&out=' + form.secondCurr.data
            return redirect(uri)
    return render_template('main.html', form=form, dollarRates=dollarRates, today=today)
コード例 #5
0
ファイル: app.py プロジェクト: rafalgrm/CryptoIntegrator
def display_prices_history(coin_symbol):
    form = MainForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            name = request.form['crypto_name']
            return redirect('/prices/history/monthly/' + name)
    data = get_prices_history_monthly(coin_symbol)
    return render_template('coins/history.html',
                           values_usd=data['values_usd'],
                           values_eur=data['values_eur'],
                           labels=data['labels'],
                           symbol=coin_symbol)
コード例 #6
0
ファイル: views.py プロジェクト: rdl-telecom/rebooter
def api_root():
	if username == 'unknown':
		return redirect('/login')
	form = MainForm()
	if form.validate_on_submit():
		for device in form.devices.data:
			device_params = form.get_device(device)
			if icomera.reboot(device_params['ip'], form.configure.data):
				flash('Перезагружаю ' + device_params['name'], category='ok')
			else:
				flash('Не могу подключиться к ' + device_params['name'], category='error')
	return render_template('index.html', title = username, username = fullname, form = form)
コード例 #7
0
ファイル: views.py プロジェクト: rdl-telecom/rebooter
def api_root():
    if username == 'unknown':
        return redirect('/login')
    form = MainForm()
    if form.validate_on_submit():
        for device in form.devices.data:
            device_params = form.get_device(device)
            if icomera.reboot(device_params['ip'], form.configure.data):
                flash('Перезагружаю ' + device_params['name'], category='ok')
            else:
                flash('Не могу подключиться к ' + device_params['name'],
                      category='error')
    return render_template('index.html',
                           title=username,
                           username=fullname,
                           form=form)
コード例 #8
0
ファイル: views.py プロジェクト: yquansah/spotify_example
def main():
    main_form = MainForm()
    message = None
    # post method for main form to work with spotify API
    if main_form.validate_on_submit():
        search_name = main_form.search_name.data
        first_query = spotify.search('artist', search_name,
                                     session.get('auth_header'))

        if (len(first_query[spotify.SPOTIFY_ARTISTS][spotify.SPOTIFY_ITEMS]) ==
                0):
            return redirect(url_for('bad_query'))

        artist_id = first_query[spotify.SPOTIFY_ARTISTS][
            spotify.SPOTIFY_ITEMS][0][spotify.SPOTIFY_ID]

        # getting related artists for a specific artist
        second_query = spotify.get_related_artists(artist_id,
                                                   session.get('auth_header'))
        rel_artists = []
        for artist in second_query[spotify.SPOTIFY_ARTISTS]:
            rel_artists.append(artist['name'])

        if len(rel_artists) > 10:
            rel_artists = rel_artists[:10]

        # getting top tracks for a specific artist
        third_query = spotify.get_artists_top_tracks(
            artist_id, session.get('auth_header'))
        top_tracks = []
        for track in third_query[spotify.SPOTIFY_TRACKS]:
            top_tracks.append(track['name'])

        if len(top_tracks) > 10:
            top_tracks = top_tracks[:10]

        db.db.artist.insert({
            "name": search_name,
            "related_artists": rel_artists,
            "top_tracks": top_tracks
        })

        return redirect(url_for('user'))
    return render_template('main.html', main_form=main_form)
コード例 #9
0
ファイル: index.py プロジェクト: mhlinder/chronofile
def index():
    form = MainForm()
    if request.method == 'POST' and form.validate_on_submit():
        db = get_db()
        posts = db.posts

        post = {
                "rectype": str(form.rectype.data),
                "book_title": str(form.book_title.data),
                "book_author": str(form.book_author.data),
                "bevtype": str(form.bevtype.data),
                "bevtype_other": str(form.bevtype_other.data),
                "time": asctime()
                }

        if post['bevtype'] == 'bevtype':
            post['bevtype'] = ""

        posts.insert(post)
        flash('Successfully saved!')
    return render_template('index.html',form=form)
コード例 #10
0
ファイル: app.py プロジェクト: rafalgrm/CryptoIntegrator
def index():
    form = MainForm()

    if request.method == 'POST':
        result = cache.get('result')
        if result is None:
            result = get_tweets(app, TWEET_LIMIT)
        if form.validate_on_submit():
            name = request.form['crypto_name']
            results, sentiment, avg_sentiment = get_coin_sentiment_data(name)
            return render_template('index.html',
                                   messages=result,
                                   form=form,
                                   crypto_name=name,
                                   sentiment={
                                       'result': enumerate(results),
                                       'sentiment': sentiment,
                                       'avg_sent': avg_sentiment
                                   })
    else:
        result = get_tweets(app, TWEET_LIMIT)
        cache.set('result', result, 300)
        return render_template('index.html', messages=result, form=form)
コード例 #11
0
def root():
    form = MainForm()
    if form.validate_on_submit():
        return redirect(form.authorizeTransaction())
    return render_template('base.html', title='Kinect Sentry Gun', form=form)