This site is developed to XHTML and CSS2 W3C standards.
If you see this paragraph, your browser does not support those standards and you
need to upgrade. Visit WaSP
for a variety of options.
Paste #682
Posted by: jjj
Posted on: 2026-05-13 00:32:05
Age: 14 hrs ago
Views: 7
import requests
import time
import subprocess
from datetime import datetime
import sys
# ==================== НАСТРОЙКИ ====================
CHECK_INTERVAL = 1.0 # секунды
# ===================================================
API_URL = "http://twitbirth.downgrade-net.ru/api.php?public_timeline.json"
last_post_id = None
def send_notification(title, message):
"""Уведомление + звук для MATE/GNOME"""
try:
subprocess.run([
'notify-send',
'--icon=dialog-information',
'--urgency=normal',
'--expire-time=10000',
title,
message
], stderr=subprocess.DEVNULL)
except:
pass
# Звук
try:
subprocess.run(['canberra-gtk-play', '-i', 'message'], stderr=subprocess.DEVNULL)
except:
try:
subprocess.run(['paplay', '/usr/share/sounds/freedesktop/stereo/message.oga'], stderr=subprocess.DEVNULL)
except:
pass
def main():
global last_post_id
print("Мониторинг публичной ленты Twitbirth запущен...")
print("Нажми Ctrl+C для остановки\n")
while True:
try:
resp = requests.get(API_URL, timeout=10)
if resp.status_code == 200 and resp.content.strip():
posts = resp.json()
new_posts = []
current_max_id = last_post_id
for post in posts:
post_id = post.get('id')
if not post_id:
continue
# Первый запуск
if last_post_id is None:
last_post_id = max((p.get('id', 0) for p in posts), default=0)
print(f"Первый запуск. Запомнили последний ID: {last_post_id}")
break
if post_id > last_post_id:
new_posts.append(post)
if post_id > (current_max_id or 0):
current_max_id = post_id
# Обновляем последний ID
if current_max_id and current_max_id > (last_post_id or 0):
last_post_id = current_max_id
# Показываем новые посты
for post in reversed(new_posts):
user = post.get('user', {}).get('name') or post.get('user', {}).get('username') or "Unknown"
text = post.get('text', '').strip()
send_notification(f"Новый пост — {user}", text)
print(f"[{datetime.now().strftime('%H:%M:%S')}] {user}: {text}")
else:
print(f"[{datetime.now().strftime('%H:%M:%S')}] Ошибка {resp.status_code}")
except requests.exceptions.RequestException as e:
print(f"[{datetime.now().strftime('%H:%M:%S')}] Ошибка соединения: {e}")
except Exception as e:
print(f"[{datetime.now().strftime('%H:%M:%S')}] Ошибка: {e}")
time.sleep(CHECK_INTERVAL)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nМониторинг остановлен.")
sys.exit(0)
Download raw |
Create new paste