Merge branch 'main' into main

This commit is contained in:
kilyabin
2026-03-01 14:09:26 +04:00
committed by GitHub
26 changed files with 701 additions and 206 deletions

View File

@@ -5,20 +5,20 @@ import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from itd import ITDClient, StreamConnect, StreamNotification
from itd import ITDClient, StreamConnect
def main():
cookies = 'YOUR_COOKIES_HERE'
if cookies == 'YOUR_COOKIES_HERE':
print('! Укажите cookies в переменной cookies')
print(' См. examples/README.md для инструкций')
return
client = ITDClient(cookies=cookies)
print('-- Подключение к SSE...')
try:
for event in client.stream_notifications():
if isinstance(event, StreamConnect):
@@ -29,7 +29,7 @@ def main():
if event.preview:
preview = event.preview[:50] + '...' if len(event.preview) > 50 else event.preview
print(f' {preview}')
except KeyboardInterrupt:
print(f'\n! Отключение...')

View File

@@ -5,48 +5,48 @@ import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from itd import ITDClient, StreamConnect, StreamNotification
from itd import ITDClient, StreamConnect
from itd.enums import NotificationType
def main():
cookies = 'YOUR_COOKIES_HERE'
if cookies == 'YOUR_COOKIES_HERE':
print('! Укажите cookies в переменной cookies')
print(' См. examples/README.md для инструкций')
return
client = ITDClient(cookies=cookies)
# Настройка: какие типы уведомлений показывать
SHOW_TYPES = {
NotificationType.LIKE,
NotificationType.FOLLOW,
NotificationType.COMMENT,
NotificationType.COMMENT
}
print('-- Подключение к SSE...')
print(f'-- Фильтр: {", ".join(t.value for t in SHOW_TYPES)}\n')
try:
for event in client.stream_notifications():
if isinstance(event, StreamConnect):
print(f'✅ Подключено! User ID: {event.user_id}\n')
continue
if event.type not in SHOW_TYPES:
continue
# Обработка разных типов
if event.type == NotificationType.LIKE:
print(f'❤️ {event.actor.display_name} лайкнул ваш пост')
elif event.type == NotificationType.FOLLOW:
print(f'👤 {event.actor.display_name} подписался на вас')
elif event.type == NotificationType.COMMENT:
print(f'💬 {event.actor.display_name}: {event.preview}')
except KeyboardInterrupt:
print(f'\n! Отключение...')

View File

@@ -5,29 +5,29 @@ import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from itd import ITDClient, StreamConnect, StreamNotification
from itd import ITDClient, StreamConnect
from datetime import datetime
import json
def main():
cookies = 'YOUR_COOKIES_HERE'
if cookies == 'YOUR_COOKIES_HERE':
print('! Укажите cookies в переменной cookies')
print(' См. examples/README.md для инструкций')
return
client = ITDClient(cookies=cookies)
log_file = f'notifications_{datetime.now().strftime("%Y%m%d_%H%M%S")}.log'
print(f'-- Подключение к SSE...')
print(f'-- Логирование в: {log_file}\n')
try:
with open(log_file, 'w', encoding='utf-8') as f:
for event in client.stream_notifications():
timestamp = datetime.now().isoformat()
if isinstance(event, StreamConnect):
log_entry = {
'timestamp': timestamp,
@@ -49,10 +49,10 @@ def main():
'target_id': str(event.target_id) if event.target_id else None
}
print(f'* {event.type.value}: {event.actor.username}')
f.write(json.dumps(log_entry, ensure_ascii=False) + '\n')
f.flush()
except KeyboardInterrupt:
print(f'\n! Отключение... Лог сохранен в {log_file}')

View File

@@ -6,19 +6,17 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
import threading
import time
from itd import ITDClient, StreamConnect, StreamNotification
from itd import ITDClient, StreamConnect
def main():
cookies = 'YOUR_COOKIES_HERE'
cookies = 'YOUR_COOKIES_HERE'
if cookies == 'YOUR_COOKIES_HERE':
print('! Укажите cookies в переменной cookies')
return
client = ITDClient(cookies=cookies)
# Функция для прослушивания в отдельном потоке
def listen():
print('! Начинаем прослушивание...')
try:
@@ -29,17 +27,16 @@ def main():
print(f'🔔 {event.type.value}: {event.actor.username}')
except Exception as e:
print(f'! Ошибка: {e}')
# В отдельном потоке
thread = threading.Thread(target=listen, daemon=True)
thread.start()
print('Прослушивание запущено. Нажмите Enter для остановки...')
input()
print('!! Останавливаем прослушивание...')
client.stop_stream()
thread.join(timeout=5)
print('! Остановлено')