import requests
country_region_operator = requests.get(f"https://fincalculator.ru/api/tel/46729047511")
cro_data = country_region_operator.json()
rus = {"region":"Регион", "country":"Страна", "operator":"Оператор", "phone":"Телефон"}
for k, v in cro_data.items():
if v and rus.get(k):
print(f'{rus.get(k)}: {v}')
KINGDOMS = {1: 'флора', 2: 'фауна'}
class SpeciesForm(FlaskForm):
find = StringField(validators=[Optional(strip_whitespace=True)], default='')
kingdom = RadioField('Выберите растения или животных', coerce=int, choices=KINGDOMS.items())
button = SubmitField('фильтр')
class SearchForm(FlaskForm):
kingdom = StringField(validators=[Optional(strip_whitespace=True)])
find = StringField('название', validators=[DataRequired(message='Обязательное поле')], default='')
findButton = SubmitField('найти')
@app.route('/species', methods=['GET', 'POST'])
def species():
form1 = SpeciesForm()
form2 = SearchForm()
if form2.validate_on_submit():
search = Species.query.filter(Species.name.like(f'%{form2.find.data}%')).all()
species_result = Species.query.filter_by(kingdom_id=form1.kingdom.data).all()
return render_template('species.html', search=search, species_result=species_result, form1=form1, form2=form2)
if form1.validate_on_submit():
species_result = Species.query.filter_by(kingdom_id=form1.kingdom.data).all()
return render_template('species.html', species_result=species_result, form1=form1, form2=form2)
return render_template('species.html', form1=form1, form2=form2)
<div id="content">
<div class="items">
<form action="" method="POST">
{{ form1.hidden_tag() }}
<div class="item" style="width: 400px">
{{ form1.kingdom.label }} {{ form1.kingdom() }}
<br><br>
{{ form1.button }}
<br><br>
<b>
{% for species in species_result %}
{{ species.name }} <br>
{% endfor %}
</b>
</div>
{{ form2.find(value=form2.find.data, type="hidden") }}
</form>
<form action="" method="POST">
{{ form2.hidden_tag() }}
<div class="item" style="width: 400px">
<i>Введите вид растения или животного</i>
<br><br>
{{ form2.find.label }} {{ form2.find() }}
<br><br>
{{ form2.findButton }}
<br><br>
{% for species in search %}
<b> {{ species.name }} </b> -> {{ species.genus.name }} -> {{ species.family.name }} ->
{{ species.order.name }} -> {{ species.class.name }} -> {{ species.divisionOrPhylum.name }} ->
{{ species.kingdom.name }} <br>
{% endfor %}
</div>
{{ form2.kingdom(value=form1.kingdom.data, type="hidden") }}
</form>
</div>
</div>
<div id="content">
<form action="" method="POST">
{{ form1.hidden_tag() }}
<div class="items">
<div class="item">
{{ form1.kingdom.label }} {{ form1.kingdom() }}
<br><br>
{{ form1.button }}
<br><br>
<b>
{% for id, name, genus_id, family_id, order_id, class_id, divisionOrPhylum_id, kingdom_id in species_result %}
{{ name }} <br>
{% endfor %}
</b>
</div>
</div>
</form>
<form action="" method="POST">
{{ form2.hidden_tag() }}
<div class="items">
<div class="item">
<i>Введите вид растения или животного</i>
<br><br>
{{ form2.find.label }} {{ form2.find() }}
<br><br>
{{ form2.findButton }}
<br><br>
{% for species in search %}
<b> {{ species.name }} </b> -> {{ species.genus.name }} -> {{ species.family.name }}<br>
{% endfor %}
</div>
</div>
</form>
</div>
@app.route('/species', methods=['GET', 'POST'])
def species():
form1 = SpeciesForm()
form2 = SearchForm()
if form1.validate_on_submit():
print(form1.kingdom.data)
species_result = list(db.engine.execute('SELECT * FROM Species WHERE kingdom_id=:kingdom_id', {'kingdom_id': form1.kingdom.data}))
return render_template('species.html', species_result=species_result, form1=form1, form2=form2)
if form2.validate_on_submit():
search = Species.query.filter(Species.name.like(f'%{form2.find.data}%')).all()
return render_template('species.html', search=search, form1=form1, form2=form2)
return render_template('species.html', form1=form1, form2=form2)