示例#1
0
from flask import Flask, render_template
from modules import convert_to_dict, make_ordinal

app = Flask(__name__)
application = app

# create a list of dicts from a CSV
offenders_list = convert_to_dict("thelist.csv")

# create a list of tuples in which the first item is the number
# (Cant) and the second item is the name (git)
pairs_list = []
for p in offenders_list:
    pairs_list.append( (p['Position'], p['Idiot']) )

# first route

@app.route('/')
def index():
    return render_template('index.html', pairs=pairs_list, the_title="The Hit List")

# second route

@app.route('/cant/<num>')
def detail(num):
    try:
        offenders_dict = offenders_list[int(num) - 1]
    except:
        return f"<h1>Invalid value for Position: {num}</h1>"
    # a little bonus function, imported on line 2 above
    ord = make_ordinal( int(num) )
示例#2
0
from flask import Flask, render_template
from modules import convert_to_dict, make_ordinal

app = Flask(__name__)

# create a list of dicts
presidents_list = convert_to_dict("presidents.csv")

# first route


@app.route('/')
def index():
    ids_list = []
    name_list = []
    # fill one list with the number of each presidency and
    # fill the other with the name of each president
    for president in presidents_list:
        ids_list.append(president['Presidency'])
        name_list.append(president['President'])
        # zip() is a built-in function that combines lists
        # creating a new list of tuples
    pairs_list = zip(ids_list, name_list)
    # sort the list by the first item in each tuple, the number
    # pairs_list_sorted = sorted(pairs_list, key=lambda tup: int(tup[0]))
    return render_template('index.html',
                           pairs=pairs_list,
                           the_title="Presidents Index")


# second route
示例#3
0
from flask import Flask, render_template
from modules import convert_to_dict

app = Flask(__name__)

ceos_list = convert_to_dict("ceos.csv")


@app.route('/')
def index():
    number_list = []
    name_list = []
    for ceo in ceos_list:
        number_list.append(ceo['number'])
        name_list.append(ceo['name'])
    pairs_list = zip(number_list, name_list)
    return render_template('index.html',
                           pairs=pairs_list,
                           the_title="Ceos Index")


@app.route('/ceo/<num>')
def detail(num):
    for ceo in ceos_list:
        if ceo['number'] == num:
            ceos_dict = ceo
            break
    return render_template('ceo.html',
                           ceo=ceos_dict,
                           ord=ord,
                           the_title=ceos_dict['name'])
示例#4
0
from flask import Flask, render_template
from modules import convert_to_dict
app = Flask(__name__)

players_list = convert_to_dict('players2.csv')


@app.route('/')
def index():
    ids_list = []
    name_list = []
    # fill one list with the number of each presidency and
    # fill the other with the name of each president
    for player in players_list:
        ids_list.append(player['Nbr'])
        name_list.append(player['Player'])
    # players_list[0]['Player']
    # players_list[0]['Place of Birth']
    pairs_list = zip(ids_list, name_list)
    return render_template('index.html',
                           pairs=pairs_list,
                           the_title="Players Index")


# your code here
@app.route('/player/<num>')
def detail(num):
    for player in players_list:
        if player['Nbr'] == num:
            players_dict = player
            break
示例#5
0
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, RadioField
from wtforms.validators import Required

app = Flask(__name__)

# Flask-WTF requires an encryption key - the string can be anything
app.config['SECRET_KEY'] = 'C2HWGVoMGfNTBsrYQg8EcMrdTimkZfAb'

# Flask-Bootstrap requires this line
Bootstrap(app)

# create a list of dicts
kanye_list = convert_to_dict("ye.csv")


# with Flask-WTF, each web form is represented by a class
# "SearchForm" can change; "(FlaskForm)" cannot
class SearchForm(FlaskForm):
    # the choices are (value, label)
    category = RadioField('Choose a detail to search:',
                          validators=[Required()],
                          choices=[('President',
                                    'President\'s Name, e.g. John'),
                                   ('Home-state', 'Home State, e.g. Virginia'),
                                   ('Occupation', 'Occupation, e.g. Lawyer'),
                                   ('College', 'College, e.g. Harvard')])
    text = StringField('Type full or partial text to search for:',
                       validators=[Required()])
示例#6
0
from modules import convert_to_dict
brewery_list = convert_to_dict("brewapp/b.csv")


def index():
    logo_list = []
    name_list = []
    type_list = []
    address_list = []
    city_list = []
    for brewery in brewery_list[:100]:
        logo_list.append(brewery['url'])
        name_list.append(brewery['brewery'])
        type_list.append(brewery['type'])
        address_list.append(brewery['address'])
        city_list.append(brewery['city'])
    info_list = zip(logo_list, name_list, type_list, address_list, city_list)
    for info in info_list:
        if ' AL' in list(info_list[4]):
            return k
        else:
            print("no")


index()
示例#7
0
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import Required

app = Flask(__name__)

# Flask-WTF requires an encryption key - the string can be anything
app.config['SECRET_KEY'] = 'C2HWGVoMGfNTBsrYQg8EcMrdTimkZfAb'

# Flask-Bootstrap requires this line
Bootstrap(app)

# create a list of dicts
movies_list = convert_to_dict("movies_clean.csv")


# create a class for the form
class SearchForm(FlaskForm):
    text = StringField('Type full or partial text to search for:',
                       validators=[Required()])
    submit = SubmitField('Search')


# first route for search aka sort of like homepg
@app.route('/', methods=['GET', 'POST'])
def search():
    form = SearchForm()
    message = ""
示例#8
0
from flask import Flask, render_template
from modules import convert_to_dict, make_ordinal
from flask_bootstrap import Bootstrap

app = Flask(__name__)

application = app

senator_list = convert_to_dict("florida-senators.csv")

Bootstrap(app)


@app.route('/')
def index():
    ids_list = []
    name_list = []

    for senator in senator_list:
        ids_list.append(senator['District'])
        name_list.append(senator['Senator'])

    pairs_list = zip(ids_list, name_list)
    return render_template('index.html',
                           pairs=pairs_list,
                           the_title="Florida Senator Index")


@app.route('/senator/<num>')
def detail(num):
    for senator in senator_list:
示例#9
0
from flask import Flask, render_template, url_for
from modules import convert_to_dict
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm

app = Flask(__name__)
application = app

#create new secret key
app.config['SECRET_KEY'] = 'C2HWGVoMGfNTBsrYQg8EcMrdTimkZfAb'

Bootstrap(app)

songs_list = convert_to_dict("songs.csv")


@app.route('/')
def index():
    num_list = []
    name_list = []
    # fill one list with the number of each presidency and
    # fill the other with the name of each president
    for li in songs_list:
        num_list.append(li['Rank'])
        name_list.append(li['Song-Name'])
        # zip() is a built-in function that combines lists
        # creating a new list of tuples
    pairs_list = zip(num_list, name_list)
    # sort the list by the first item in each tuple, the number
    # pairs_list_sorted = sorted(pairs_list, key=lambda tup: int(tup[0]))
    return render_template('index.html',
示例#10
0
from flask import Flask, render_template
from modules import convert_to_dict
from flask_bootstrap import Bootstrap

app = Flask(__name__)
Bootstrap(app)

elements_list = convert_to_dict("Periodic_Table.csv")


@app.route('/')
def index():
    ids_list = []
    name_list = []
    for element in elements_list:
        ids_list.append(element['atomic_number'])
        name_list.append(element['name'])
    pairs_list = zip(ids_list, name_list)

    return render_template('index.html',
                           pairs=pairs_list,
                           the_title="List of Elements")


@app.route('/element/<num>')
def detail(num):
    for element in elements_list:
        if element['atomic_number'] == num:
            elem_dict = element
            break
    return render_template('element.html',
示例#11
0
from flask import Flask, render_template, url_for
from modules import convert_to_dict

from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm

app = Flask(__name__)

app.config['SECRET_KEY'] = 'secret key goes here'
#change this

Bootstrap(app)

games_list = convert_to_dict("newGames.csv")


@app.route("/")
def index():
    ids_list = []
    name_list = []

    for games in games_list:
        ids_list.append(games['id'])
        name_list.append(games['game'])
    pairs_list = zip(ids_list, name_list)
    return render_template('index.html',
                           pairs=pairs_list,
                           the_title="Games Index")


@app.route('/games/<num>')
示例#12
0
from flask import Flask, render_template, redirect, url_for, request
from flask_bootstrap import Bootstrap
from modules import convert_to_dict
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import Required

app = Flask(__name__)

application = app

Bootstrap(app)

app.config['SECRET_KEY'] = '9iUH02Y7Dq'

destinations = convert_to_dict("destination.csv")
cultures = convert_to_dict("culturePractice.csv")
heritages = convert_to_dict("heritage5.csv")


def get_id(source, name):
    for row in source:
        if name.lower() == row["Name"].lower():
            id = row["code"]
            return id
        return "Unknown"


class NameForm(FlaskForm):
    text = StringField('What country are you traveling to?',
                       validators=[Required()])
示例#13
0
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import Required

app = Flask(__name__)

# Flask-WTF requires an encryption key - the string can be anything
app.config['SECRET_KEY'] = 'C2HWGVoMGfNTBsrYQg8EcMrdTimkZfAb'

# Flask-Bootstrap requires this line
Bootstrap(app)

# create a list of dicts
movies_list = convert_to_dict("movies_all.csv")

# create a class for the form
class SearchForm(FlaskForm):
    text = StringField('Type full or partial text to search for:', validators=[Required()] )
    submit = SubmitField('Search')


# first route for index

@app.route('/')
def index():
    ids_list = []
    name_list = []
    # fill one list with the number of each movie number and
    # fill the other with the name of each movie
示例#14
0
from flask import Flask, render_template, redirect, url_for, request
from modules import convert_to_dict, make_ordinal

from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import SubmitField, SelectField
from wtforms.validators import Required

app = Flask(__name__)
application = app

app.config['SECRET_KEY'] = 'VguhZssWgM'

Bootstrap(app)

members_list = convert_to_dict("flask_rep_info.csv")
state_financial_list = convert_to_dict("state_financial_info.csv")


class SearchForm(FlaskForm):
    state_choice = SelectField('Select from this list.')
    submit = SubmitField('Search')


@app.route('/', methods=['GET', 'POST'])
def index():
    state_list = []
    second_state_list = []
    pairs_list = []
    for state in state_financial_list:
        state_list.append(state['state'])
示例#15
0
from modules import convert_to_dict
from modules import convert_to_dict, make_ordinal

from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import Required

app = Flask(__name__)

# Flask-WTF requires an encryption key - the string can be anything
app.config['SECRET_KEY'] = '--'


# create a list of dicts
actor_list = convert_to_dict("actors.csv")


# first route

@app.route('/')
def index():
    ids_list = []
    name_list = []
    # fill one list with the number of each presidency and
    # fill the other with the name of each president
    for actor in actor_list:
        ids_list.append(actor['Number'])
        name_list.append(actor['Actor'])
        # zip() is a built-in function that combines lists
        # creating a new list of tuples
示例#16
0
from flask import Flask, render_template
from modules import convert_to_dict
app = Flask(__name__)

application = app

collegeList = convert_to_dict("public3.csv")


@app.route('/')
def index():
    ids = []
    names = []
    for college in collegeList:
        ids.append(college['Id'])
        names.append(college['Name'])
    pairs_list = zip(ids, names)
    return render_template('index.html',
                           pairs=pairs_list,
                           the_title="Colleges")


@app.route('/college/<num>')
def detail(num):
    for college in collegeList:
        if college['Id'] == num:
            collegeDict = college
            break
    return render_template('college.html',
                           c=collegeDict,
                           the_title=collegeDict['Name'])