chore: update version; move scripts into examples folder
This commit is contained in:
@@ -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}')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user