python3 path/manage.py convert_next_video
import re
def get_substrings(string):
"""Функция разбивки на слова"""
return re.split('\W+', string)
def get_distance(s1, s2):
"""Расстояние Дамерау-Левенштейна"""
d, len_s1, len_s2 = {}, len(s1), len(s2)
for i in range(-1, len_s1 + 1):
d[(i, -1)] = i + 1
for j in range(-1, len_s2 + 1):
d[(-1, j)] = j + 1
for i in range(len_s1):
for j in range(len_s2):
if s1[i] == s2[j]:
cost = 0
else:
cost = 1
d[(i, j)] = min(
d[(i - 1, j)] + 1,
d[(i, j - 1)] + 1,
d[(i - 1, j - 1)] + cost)
if i and j and s1[i] == s2[j - 1] and s1[i - 1] == s2[j]:
d[(i, j)] = min(d[(i, j)], d[i - 2, j - 2] + cost)
return(d[len_s1 - 1, len_s2 - 1])
def check_substring(search_request, original_text, max_distance):
"""Проверка нечёткого вхождения одного набора слов в другой"""
substring_list_1 = get_substrings(search_request)
substring_list_2 = get_substrings(original_text)
not_found_count = len(substring_list_1)
for substring_1 in substring_list_1:
for substring_2 in substring_list_2:
if get_distance(substring_1, substring_2) <= max_distance:
not_found_count -= 1
if not not_found_count:
return True
search_request = 'трубок использовали для прожигания'
original_text = 'трубок использовали для прожигания стальковша.Замена воронки 18м 8сл. Разлита полностью'
result = check_substring(search_request, original_text, max_distance=2)
print(result) # True если найдено, иначе None
Warning
The whole request parser part of Flask-RESTful is slated for removal and will be replaced by documentation on how to integrate with other packages that do the input/output stuff better (such as marshmallow). This means that it will be maintained until 2.0 but consider it deprecated. Don’t worry, if you have code using that now and wish to continue doing so, it’s not going to go away any time too soon.
result = ' '.join([
pattern.format(value) for value, pattern in zip(
(x.days, x.seconds//3600, (x.seconds//60)%60, x.seconds),
('{} д.', '{} час.', '{} мин.', '{} сек.'),
)
if value
])
pyvenv .venv
python3 -m venv .venv
python3 --help
-m mod : run library module as a script (terminates option list)
...
response = api.users.get(access_token = token, user_ids = id)
first_name = response[0]['first_name']
print(first_name)
Но меня интерисовала скорее производительность.
Так как один проект официальный, а второй нет.
self.fullscreen()
self.resize(Gdk.Screen.width(), Gdk.Screen.height())
from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver
from smartcard.CardMonitoring import CardObserver
from smartcard.util import toHexString
from smartcard.Exceptions import CardConnectionException, NoCardException
from time import sleep
class CardObserver(CardObserver):
def __init__(self, app):
self.app = app
self.connection_observer = ConsoleCardConnectionObserver()
self.has_card = False
self.rfid_tag = None
self.card = None
def update(self, observable, actions):
connected_cards, disconnected_cards = actions
if connected_cards:
self.card = connected_cards[0]
self.get_rfid_tag()
for card in disconnected_cards:
self.rfid_tag = None
self.has_card = False
self.card = None
def get_rfid_tag(self):
try:
self.card.connection = self.card.createConnection()
self.card.connection.connect()
self.card.connection.addObserver(self.connection_observer)
data, sw1, sw2 = self.card.connection.transmit([255, 202, 0, 0, 0])
data.reverse()
self.rfid_tag = toHexString(data, format=1)
self.has_card = True
except NoCardException as error:
print(error)
except AttributeError as error:
print(error)
except CardConnectionException as error:
print(error)
def rfid_tag_check_worker(self):
while True:
if self.card:
self.get_rfid_tag()
sleep(5)
rfid_tag_check_thread = Thread(target=self.rfid_card_observer.rfid_tag_check_worker)
rfid_tag_check_thread.start()
{% load static mptt_tags %}
{% recursetree category_tree %}
<li>
<a class="btn btn__light" href="{% url 'category' node.pk %}">
<span style="flex: 1 1 auto;">{{ node.name }}</span>{% if not node.is_leaf_node %}
<span> </span><span class="fa fa-angle-right"></span>{% endif %}
</a>
{% if not node.is_leaf_node %}
<ul class="site_nav_primary__submenu ul__column white_box">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
<a class="btn btn__light" href="{% url 'category' node.pk %}"></a>
{% if not node.is_leaf_node %}
<ul class="site_nav_primary__submenu ul__column white_box">
{{ children }}
</ul>
{% endif %}
{% рекурсивное_дерево дерева_категорий %}
Открываем HTML-теги для узлов верхнего уровня
и что-то делаем с узлами верхнего уровня.
{% если узел верхнего уровня содержит дочерние узлы %}
открываем html-теги, в которые хотим завернуть дочерние узлы
{{ дети }}
закрываем html-теги
{% конец если про детей %}
Если нужно, ещё что-то делаем с узлами верхнего уровня
и закрываем HTML-теги.
{% конец рекурсивного дерева %}
python3 setup.py develop
AttributeError: 'ManyToManyField' object has no attribute 'm2m_reverse_field_name'
Flask, being a microframework, often requires some repetitive steps to get a third party library working. Because very often these steps could be abstracted to support multiple projects the Flask Extension Registry was created.
Extension implementing Mako Templates support in Flask with support for flask-babel
from werkzeug.debug.tbtools import Traceback, Frame, Line
...
from mako import exceptions
from mako.exceptions import RichTraceback, text_error_template