@app.route('/')
def home():
root_dir = app.config['ROOT_DIR']
image_paths = {}
for root,dirs,files in os.walk(root_dir):
for file in files:
if any(file.endswith(ext) for ext in app.config['IMAGE_EXTS']):
image_paths[file] = encode(os.path.join(root,file))
return render_template('index.html', paths=image_paths)
{% for file, encode_file in paths.items() %}
<img src='cdn/{{ encode_file }}' height=10% width=10% onclick="clicked_img(this)" >
<div class="desc">{{ file }}</div> #<------ ВОТ ТУТ Я ХОЧУ ИМЯ ФАЙЛА
{% endfor %}
{
"update_id": 933188596,
"message": {
"message_id": 1165934,
"from": {
"id": 534905,
"is_bot": false,
"first_name": "Aleksandr",
"last_name": "Shabelsky",
"username": "shabelsky",
"language_code": "ru"
},
"chat": {
"id": 534905,
"first_name": "Aleksandr",
"last_name": "Shabelsky",
"username": "shabelsky",
"type": "private"
},
"date": 1661801219,
"text": "тест сообщения"
}
}
{
"update_id": 933188598,
"message": {
"message_id": 1165936,
"from": {
"id": 534905,
"is_bot": false,
"first_name": "Aleksandr",
"last_name": "Shabelsky",
"username": "shabelsky",
"language_code": "ru"
},
"chat": {
"id": 534905,
"first_name": "Aleksandr",
"last_name": "Shabelsky",
"username": "shabelsky",
"type": "private"
},
"date": 1661801228,
"reply_to_message": {
"message_id": 1165934,
"from": {
"id": 534905,
"is_bot": false,
"first_name": "Aleksandr",
"last_name": "Shabelsky",
"username": "shabelsky",
"language_code": "ru"
},
"chat": {
"id": 534905,
"first_name": "Aleksandr",
"last_name": "Shabelsky",
"username": "shabelsky",
"type": "private"
},
"date": 1661801219,
"text": "тест сообщения"
},
"text": "тест ответа на сообщение"
}
}
import os
import subprocess
retcode = subprocess.call(['echo', 'foo'],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
@bot.message_handler(content_types=["text"])
def send_photo(message):
if message.text == "Картиночка":
img_dir = r'C:\Projects\telebot_test_functions\photo'
images = [os.path.join(img_dir, img) for img in os.listdir(img_dir) if img.endswith('png')]
random_img = random.choice(images)
if random_img:
photo = open(random_img, 'rb')
bot.send_photo(message.chat.id, photo)
else:
bot.send_photo(message.chat.id, "нет картинки")
from random import randint
from json import JSONEncoder
class TestCase:
def __init__(self, name: str):
self.id = randint(0, 999)
self.name = name
self.steps = dict()
self.result = str()
def set_step(self, step_number: int, step_text: str):
self.steps[step_number] = step_text
def delete_step(self, step_number: int):
if self.steps.get(step_number) is not None:
self.steps.pop(step_number)
def get_steps(self) -> dict:
return self.steps
def set_result(self, result: str):
self.result = result
def get_test_case(self):
current_result = TestCaseEncoder(ensure_ascii=False, indent=4).encode(self)
print(current_result)
return current_result
class TestCaseEncoder(JSONEncoder):
def default(self, o):
json_object = {
'id': o.__dict__.get('id'),
'Название': o.__dict__.get('name'),
'Шаги': o.__dict__.get('steps'),
'Ожидаемый результат': o.__dict__.get('result')
}
return json_object
t = TestCase(name="Test")
t.set_step(1, 'Перейти на сайт')
t.set_step(2, 'Перейти в раздел Товары')
t.set_step(3, 'Нажать кнопку «В корзину» у первого товара')
t.set_result(result='Товар окажется в корзине')
t.get_test_case()
t.delete_step(2)
t.get_test_case()
self.connection = pymysql.connect(host='localhost', port=3306, user='root', password='',
db='aiodb')
self.cursor = self.connection.cursor()
class Database:
def __init__(self, config):
self.config = config
self.connection = pymysql.connect(**self.config)
def execute(self, query: str, params: tuple = None):
try:
with self.connection as connect:
cursor = connect.cursor()
if params is not None:
cursor.execute(query, params)
else:
cursor.execute(query)
return cursor.fetchall()
except OperationalError as Error:
print(Error)
class Person:
def __init__(self, name):
self.name = name
self.something_1 = 'abc'
self.something_2 = 123
def check_attr(obj, attr_name):
try:
value = obj.__getattribute__(attr_name)
return f'{obj} имеет аттрибут - {attr_name} со значением - {value}'
except AttributeError:
return f'{obj} не имеет аттрибута - {attr_name}'
if __name__ == "__main__":
p = Person(name='Alex')
print(check_attr(p, 'something_1'))
print(check_attr(p, 'something_2'))
print(check_attr(p, 'something_33333'))
import time
from random import choice
from threading import Thread
version = [
{'language': 'Навахо', 'phrase': 'Ayóó ánííníshí', 'pronunciation': 'Аийоо ианинииши'},
{'language': 'Гавайский', 'phrase': 'Aloha wau iā ʻoe', 'pronunciation': 'Алоха ва уйа ой'},
{'language': 'Бангладешский', 'phrase': 'আমিতোমাকেভালবাসি', 'pronunciation': 'Ами тумакэ палабаши'},
{'language': 'Латинский', 'phrase': 'Te amo', 'pronunciation': 'Тэ амо'},
]
def read_from_stdin():
while True:
input_phrase = input()
if input_phrase.lower() == 'love':
result = choice(version)
print(result['language'])
print(result['phrase'])
print(result['pronunciation'])
else:
print(f'unknown command - {input_phrase}')
def some_worker():
while True:
print("некая переписка")
time.sleep(5)
if __name__ == "__main__":
reader_t = Thread(target=read_from_stdin).start()
worker_t = Thread(target=some_worker).start()
try:
bot.send_message(user_id, text)
except telebot.apihelper.ApiException:
logging.exception(f'Send Notification ERROR - {telebot.apihelper.ApiException}')
delete_user(user_id)
def delete_user(user_id):
del_user_query = f'DELETE FROM {users_t} WHERE {users_col["user_id"]} = {user_id};'
post_sql_query(del_user_query)