Example #1
0
def user(username):
    user = User.query.filter_by(username=username).first_or_404()
    indexForm = IndexForm()
    checkForm = CheckForm()
    newestday = Date.query.order_by(
        Date.day.desc()).first()  # THis way our newest day is first in table
    date = newestday.day
    indexForm.date.choices = [
        (str(date.day), str(date.day))
        for date in Date.query.order_by(Date.day.desc()).all()
    ]
    usershares = StockShares.query.filter_by(date=date).join(
        UserShares,
        UserShares.user_company == StockShares.stockName).filter_by(
            user_id=current_user.id).all()
    if indexForm.submitDate.data and indexForm.validate_on_submit():
        date = indexForm.date.data
        usershares = StockShares.query.filter_by(date=date).join(
            UserShares,
            UserShares.user_company == StockShares.stockName).filter_by(
                user_id=current_user.id).all()
    return render_template('myshares.html',
                           user=user,
                           usershares=usershares,
                           indexForm=indexForm,
                           checkForm=checkForm)
Example #2
0
def index():
    form = IndexForm()
    if form.validate_on_submit():
        return redirect(url_for('game'))
    elif request.method == 'GET':
        form.language = 0
    return render_template('index.html', form=form)
Example #3
0
def index():
    form = IndexForm()
    if form.validate_on_submit(
    ):  #when form is submitted then this block of code will be run i.e. on POST
        return redirect(url_for('search', usertype=form.usertype.data))
    return render_template(
        'index1.html', title="Home",
        form=form)  #Pass the form object on top if it is a GET request
Example #4
0
def index():
    global temp_file_url
    global face_user
    form = IndexForm()

    if form.validate_on_submit() and form.submit.data:
        return redirect(url_for('add_mouth_effect'))

    if form.validate_on_submit() and form.submit_eyes.data:
        return redirect(url_for('add_eyes_effect'))

    if form.validate_on_submit() and form.default.data:
        return redirect(url_for('default'))

    temp_file_url = temp_file_url.replace('app/', '')
    phrase = welcome_phrase(face_user.mood)
    return render_template('index.html',
                           title='Home',
                           image=temp_file_url,
                           form=form,
                           welcome_phrase=phrase)
Example #5
0
def index():
    indexForm = IndexForm()
    checkForm = CheckForm()
    newestday = Date.query.order_by(
        Date.day.desc()).first()  # THis way our newest day is first in table
    date = str(newestday.day)
    shares = StockShares.query.filter_by(date=newestday.day).all()
    indexForm.date.list = ('db_dates')
    dates = Date.query.order_by(Date.day.desc()).all()
    if current_user.is_authenticated:
        usershares = StockShares.query.filter_by(date=date).join(
            UserShares,
            UserShares.user_company == StockShares.stockName).filter_by(
                user_id=current_user.id).all()
        if indexForm.submitDate.data and indexForm.validate_on_submit():
            date = indexForm.date.data
            shares = StockShares.query.filter_by(date=date).all()
            usershares = StockShares.query.filter_by(date=date).join(
                UserShares,
                UserShares.user_company == StockShares.stockName).filter_by(
                    user_id=current_user.id).all()
        return render_template('index.html',
                               title="Porzadna praca",
                               indexForm=indexForm,
                               shares=shares,
                               checkForm=checkForm,
                               usershares=usershares,
                               dates=dates)
    else:
        if indexForm.submitDate.data and indexForm.validate_on_submit():
            date = indexForm.date.data
            shares = StockShares.query.filter_by(date=date).all()
    return render_template('index.html',
                           title="Porzadna praca",
                           indexForm=indexForm,
                           shares=shares,
                           checkForm=checkForm,
                           dates=dates)
Example #6
0
def index():
    form = IndexForm()

    if form.validate_on_submit():
        
        # submit button 1: query
        if form.submit1.data:
            number_subj, new_df = query_csv(form)
            flash('Number of subjects due to your selection: {}'.format(number_subj), 'error') ### IN RED COLOUR!!!
            return render_template('index.html', form=form, result_pca=None, result_hcl=None)
        
        # submit button 2: download
        if form.submit2.data:
            number_subj, new_df = query_csv(form)
            resp = make_response(new_df.to_csv())
            resp.headers["Content-Disposition"] = "attachment; filename=export.csv"
            resp.headers["Content-Type"] = "text/csv"
            return resp  
        
        # submit button 3: PCA
        if form.submit3.data:
            number_subj, new_df = query_csv(form)
            fig_pca = pca_cnsvs_ss(new_df)
            from io import BytesIO
            import base64
            figpcafile = BytesIO()
            fig_pca.savefig(figpcafile, format='png')
            figpcafile.seek(0)  # rewind to beginning of file
            figdata_png_pca = base64.b64encode(figpcafile.getvalue())
            return render_template('index.html', form=form, result_pca=figdata_png_pca.decode('utf8'), result_hcl=None)

        # submit button 4: Clustering
        if form.submit4.data:
            number_subj, new_df = query_csv(form)
            fig_hcl = clustering_cnsvs_ss(new_df)
            from io import BytesIO
            import base64
            fighclfile = BytesIO()
            fig_hcl.savefig(fighclfile, format='png')
            fighclfile.seek(0)  # rewind to beginning of file
            figdata_png_hcl = base64.b64encode(fighclfile.getvalue())
            return render_template('index.html', form=form, result_pca=None, result_hcl=figdata_png_hcl.decode('utf8'))        
    
    
    return render_template('index.html', form=form, result=None)
    def index_submit():
        form = IndexForm()
        if request.method == 'POST':

            # check if the post request has the file part
            if 'file' not in request.files:
                flash('No file part')
                return redirect(request.url)
            file = request.files['file']
            if file.filename == '':
                flash('No file selected for uploading')
                return redirect(request.url)
            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)
                file.save(os.path.join(current_dir, "tmp", filename))

            else:
                flash('Allowed file types are txt or csv')
                return redirect(request.url)

            api_key = form.api_key.data
            if form.validate_on_submit():

                ##################################

                with open(os.path.join(current_dir, "tmp",
                                       filename)) as input_file, open(
                                           'output.csv', 'w') as output:
                    csv_reader = csv.reader(input_file, delimiter=',')
                    csv_out = csv.writer(output, delimiter=',')
                    csv_out.writerow(column_names)

                    # line_count = 0
                    for row in csv_reader:
                        if row:
                            email = row[0]
                            # line_count += 1
                            # if line_count%100 == 0:
                            #     time.sleep(30)
                            try:
                                # response = call_fullcontact(email, api_key)
                                req = urllib.request.Request(
                                    'https://api.fullcontact.com/v3/person.enrich'
                                )
                                req.add_header('Authorization',
                                               'Bearer {}'.format(api_key))

                                data = json.dumps(
                                    {"email": "{}".format(email)})

                                response = urllib.request.urlopen(
                                    req, data.encode())

                                x = response.read().decode('utf-8')
                                xx = json.loads(x)
                                # f = csv.writer(open("output.csv", "w"))
                                # f.writerow(column_names)
                                csv_out.writerow(get_csv_row(xx, email))
                            except urllib.error.HTTPError as e:
                                print('API HTTPrequest handling error{0}: {1}'.
                                      format(e.getcode(), email))
                                if e.getcode() == 403:
                                    time.sleep(300)
                                    print(
                                        'rised x-limit, so please for a while...'
                                    )
                                xx = {}
                                csv_out.writerow(get_csv_row(xx, email))
                            except urllib.error.URLError as e:
                                # Not an HTTP-specific error (e.g. connection refused)
                                # ...
                                print('URLError: {0}: {1}'.format(
                                    e.reason, email))
                                xx = {}
                                csv_out.writerow(get_csv_row(xx, email))

                    flash('Hello, Success!')

                ##################################

            else:
                flash('Error: All Fields are Required')

        # load registration template
        return render_template('index.html',
                               title='Scraper via FullContactAPI',
                               form=form)
Example #8
0
def index():
    cur.execute(
        'select username, email, type_u from Пользователи where id = %s',
        (current_user.id, ))
    user1 = cur.fetchone()
    st_gr = user1
    if user1[2] == 'Студент':
        cur.execute('select №Группы from Студент where email = %s',
                    (user1[1], ))
        st_gr = cur.fetchone()
    user = {'username': user1[0], 'role': user1[2], 'group': st_gr[0]}
    form = IndexForm()
    cur.execute(
        'select ФИО, №Зачетки,Стипендия,№Группы from Студент order by ФИО')
    students = cur.fetchall()
    if user1[2] == 'Студент':
        cur.execute('select №Зачетки from Студент where ФИО = %s',
                    (user1[0], ))
        s_number = cur.fetchone()
        cur.execute(
            'select НаучнаяРабота.Название, ТемаНаучнаяРабота.НазваниеТемы, НаучнаяРабота.ФИОНаучрук from НаучнаяРабота, ТемаНаучнаяРабота where НаучнаяРабота.Название = ТемаНаучнаяРабота.НазваниеРаботы and НаучнаяРабота.Название in (select Название from СтудентНаучнаяРабота where №Зачетки = %s);',
            (s_number))
    elif user1[2] == 'Преподаватель':
        cur.execute(
            'select НаучнаяРабота.Название, ТемаНаучнаяРабота.НазваниеТемы, НаучнаяРабота.ФИОНаучрук from НаучнаяРабота, ТемаНаучнаяРабота where НаучнаяРабота.Название = ТемаНаучнаяРабота.НазваниеРаботы and НаучнаяРабота.Название in (select Название from НаучнаяРаботаПрепод where ФИО = %s);',
            (user1[0], ))
    w = cur.fetchall()
    w1 = cur.fetchall()
    w_prep = cur.fetchall()
    w_st = cur.fetchall()
    if user1[2] == 'Преподаватель':
        cur.execute(
            'select НазваниеРаботы, НазваниеТемы from ТемаНаучнаяРабота where НазваниеРаботы in (select Название from НаучнаяРабота where ФИОНаучрук = %s)',
            (user1[0], ))
        w1 = cur.fetchall()
        cur.execute('select * from НаучнаяРаботаПрепод')
        w_prep = cur.fetchall()
        cur.execute(
            'select СтудентНаучнаяРабота.Название, Студент.ФИО from СтудентНаучнаяРабота, Студент where СтудентНаучнаяРабота.№Зачетки = Студент.№Зачетки'
        )
        w_st = cur.fetchall()
    if form.validate_on_submit():
        if form.submit.data == True:
            if form.group.data == '':
                flash('Вы не ввели номер группы!')
                return redirect('/index')
            cur.execute('select * from Группа where №Группы = %s;',
                        (form.group.data, ))
            g = cur.fetchone()
            if g is None:
                cur.execute('insert into Группа values (%s);',
                            (form.group.data, ))
                con.commit()
                flash('Группа добавлена!')
                return redirect('/index')
            else:
                flash('Такая группа уже существует!')
                return redirect('/index')
        elif form.submit_s.data == True:
            if form.grant.data == '':
                form.grant.data = 0
            if int(form.grant.data) == 0:
                cur.execute(
                    'update Студент set Стипендия = %s where №Зачетки = %s', (
                        None,
                        form.s_num.data,
                    ))
            else:
                cur.execute(
                    'update Студент set Стипендия = %s where №Зачетки = %s', (
                        form.grant.data,
                        form.s_num.data,
                    ))
            con.commit()
            flash('Стипендия изменена!')
            return redirect('/index')
        elif form.submit_st_del.data == True:
            cur.execute('select email from Студент where №Зачетки = %s',
                        (form.st_del_id.data, ))
            email = cur.fetchone()
            cur.execute('delete from СтудентНаучнаяРабота where №Зачетки = %s',
                        (form.st_del_id.data, ))
            cur.execute('delete from Студент where №Зачетки = %s',
                        (form.st_del_id.data, ))
            cur.execute('delete from Пользователи where email = %s', (email, ))
            con.commit()
        elif form.gr_del.data == True:
            cur.execute('select ФИО from Студент where №Группы = %s',
                        (form.gr_del_num.data, ))
            st_in_gr = cur.fetchone()
            if st_in_gr is None:
                cur.execute('delete from Группа where №Группы = %s',
                            (form.gr_del_num.data, ))
                con.commit()
            else:
                flash('В этой группе еще продолжают учиться студенты!')
        elif form.prep_del_s.data == True:
            cur.execute('delete from НаучнаяРаботаПрепод where ФИО = %s',
                        (form.prep_del.data, ))
            cur.execute(
                'select Название from НаучнаяРабота where ФИОНаучрук = %s',
                (form.prep_del.data, ))
            prep_del = cur.fetchone()
            if prep_del is not None:
                cur.execute(
                    'delete from СтудентНаучнаяРабота where Название in (select Название from НаучнаяРабота where ФИОНаучрук = %s)',
                    (form.prep_del.data, ))
                cur.execute(
                    'delete from Участие where НазваниеРаботы in (select Название from НаучнаяРабота where ФИОНаучрук = %s)',
                    (form.prep_del.data, ))
                cur.execute(
                    'delete from ТемаНаучнаяРабота where НазваниеРаботы in (select Название from НаучнаяРабота where ФИОНаучрук = %s)',
                    (form.prep_del.data, ))
                cur.execute('delete from НаучнаяРабота where ФИОНаучрук = %s',
                            (form.prep_del.data, ))
            cur.execute('delete from Преподаватель where ФИО = %s',
                        (form.prep_del.data, ))
            cur.execute('delete from Пользователи where username = %s',
                        (form.prep_del.data, ))
            flash('Преподаватель %s уволен!', (form.prep_del.data))
    cur.execute(
        'select ФИО, №Зачетки,Стипендия,№Группы from Студент order by ФИО')
    students = cur.fetchall()
    cur.execute('select * from Преподаватель')
    prep = cur.fetchall()
    cur.execute('select * from Группа order by №Группы')
    gr = cur.fetchall()
    return render_template('index.html',
                           title='Научные работы',
                           user=user,
                           form=form,
                           w=w,
                           w1=w1,
                           students=students,
                           w_prep=w_prep,
                           w_st=w_st,
                           gr=gr,
                           prep=prep)
Example #9
0
def index():
    form = IndexForm()
    if form.validate_on_submit():
	return redirect(url_for('index'), points = form.points.data, rebounds = form.rebounds.data, assists = form.assists.data, steals = form.steals.data, blocks = form.blocks.data, three = form.threes.data, fgp = form.fgp.data, fga = form.fga.data, ftp = form.ftp.data, fta = form.fta.data, turnovers = form.turnovers.data)
    return render_template('index.html', title='Home', form=form)