Files
gitadmin 251fa0be11
ci/woodpecker/push/woodpecker Pipeline was successful
реструктуризация файлов проекта
2026-08-30 10:08:43 +03:00

76 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""LEGACY — не входит в пайплайн runner.sh с версии 1.0.0.
Проставляет marked_to_publication = 1 видимым событиям (is_visible = 1),
у которых флаг ещё не установлен.
Запуск вручную из корня проекта:
./venv/bin/python tools/legacy/evt_prefetch.py
"""
import os
import mysql.connector
from mysql.connector import Error
from dotenv import load_dotenv
_PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
load_dotenv(os.path.join(_PROJECT_ROOT, ".env"))
load_dotenv()
MDB_HOST = os.getenv('MDB_HOST')
MDB_USER = os.getenv('MDB_USER')
MDB_PW = os.getenv('MDB_PW')
MDBASE = os.getenv('MDBASE')
def prefetch_all_events():
"""
Проверяет записи в таблице events и устанавливает флаг marked_to_publication
для записей, которые:
- имеют флаг is_visible = 1
- не имеют флага marked_to_publication = 1
"""
try:
connection = mysql.connector.connect(
host=MDB_HOST,
user=MDB_USER,
password=MDB_PW,
database=MDBASE
)
cursor_temp = connection.cursor()
cursor_temp.execute("SET time_zone = '+00:00'")
cursor_temp.close()
cursor = connection.cursor()
update_query = """
UPDATE events
SET marked_to_publication = 1
WHERE is_visible = 1
AND marked_to_publication = 0
"""
cursor.execute(update_query)
updated_count = cursor.rowcount
connection.commit()
print(f"Обновлено записей: {updated_count}")
return updated_count
except Error as e:
print(f"Ошибка базы данных: {e}")
if 'connection' in locals() and connection.is_connected():
connection.rollback()
return 0
except Exception as e:
print(f"Общая ошибка: {e}")
return 0
finally:
if 'connection' in locals() and connection.is_connected():
cursor.close()
connection.close()
if __name__ == "__main__":
prefetch_all_events()