Skip to content

Instantly share code, notes, and snippets.

@lananovikova10
Created October 23, 2021 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lananovikova10/bc38f15c2b69c2230a9f68b8dca0e643 to your computer and use it in GitHub Desktop.
Save lananovikova10/bc38f15c2b69c2230a9f68b8dca0e643 to your computer and use it in GitHub Desktop.
def get_countries_rosturizm():
url = "https://city.russia.travel/safety/kakie_strany_otkryty/"
html = get_html(url)
if html:
data = get_accepted_countries(html)
return data
else:
return None
def get_html(url):
try:
result = requests.get(url)
result.raise_for_status()
return result.text
except(requests.RequestException, ValueError):
return None
def get_accepted_countries(html):
all_published_countries = []
open_countries = []
soup = BeautifulSoup(html, 'html.parser')
all_published_countries = soup.findAll('a', style='color:#1f4cff !important;')
print(all_published_countries)
for country_object in all_published_countries:
open_countries.append(country_object.text)
open_countries.sort()
return open_countries
---
{% extends "base.html" %}
{% block content %}
<h1>{{ page_title }}</h1>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-9">
<h3>{{ title }}</h3>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="alert alert-warning" role="alert">
{{ messages[-1] }}<br>
</div>
{% endif %}
{% endwith %}
<br><br>
<p>
<div class="col-sm-9">
<div class="container">
<ul class="list-group">
{% for country in countries_list %}
<li class="list-group-item"><a href="{{ url_for('country_related.country_request', identifier=identifier) }}">{{ country }}</a></li>
{% endfor %}
</ul>
</div>
</p>
<h3><a href="{{ url_for('main_page.display') }}">на главную</a></h3>
</div>
</div>
{% endblock %}
---
@blueprint.route('/country_list')
def get_open_countries():
title = f"Какие страны открыты для россиян"
countries_list = get_countries_rosturizm()
countries_data = {}
country_to_id_mapping = []
for country in countries_list:
country = Country.query.filter_by(country_name=country).first()
if country.id == None:
print(country.id)
else:
countries_data['country_id']=country.id
countries_data['country_name']=country
country_to_id_mapping.append(countries_data)
log.logging.info(country_to_id_mapping)
return render_template('country/country_list.html', page_title=title, countries_list=countries_list)
---
@blueprint.route('/country_request/<identifier>')
@login_required
def country_request(identifier):
---
from webapp.countries_rosturizm import get_countries_rosturizm
--
db.session.add(choice)
db.session.commit()
country = Country.query.filter_by(country_name=select_arr).first()
print(country.id)
return redirect(url_for('country_related.country_request', identifier=country.id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment