add set of pages to watch

This commit is contained in:
Tykayn 2025-09-01 00:14:00 +02:00 committed by tykayn
parent 77ad76cc7e
commit 7a7704bc01
22 changed files with 216839 additions and 6049 deletions

View file

@ -26,6 +26,7 @@ import logging
import os
from datetime import datetime
import requests
import re
# Configure logging
logging.basicConfig(
@ -35,10 +36,52 @@ logging.basicConfig(
)
logger = logging.getLogger(__name__)
# Function to read variables from .env file
def read_env_file(env_file_path=".env"):
"""
Read environment variables from a .env file
Args:
env_file_path (str): Path to the .env file
Returns:
dict: Dictionary of environment variables
"""
env_vars = {}
try:
with open(env_file_path, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
# Skip comments and empty lines
if not line or line.startswith('#'):
continue
# Match variable assignments (KEY=VALUE)
match = re.match(r'^([A-Za-z0-9_]+)=(.*)$', line)
if match:
key, value = match.groups()
# Remove quotes if present
value = value.strip('\'"')
env_vars[key] = value
logger.info(f"Successfully loaded environment variables from {env_file_path}")
return env_vars
except IOError as e:
logger.error(f"Error reading .env file {env_file_path}: {e}")
return {}
# Constants
OUTDATED_PAGES_FILE = "outdated_pages.json"
MASTODON_API_URL = "https://mastodon.instance/api/v1/statuses" # Replace with actual instance
MASTODON_ACCESS_TOKEN = os.environ.get("MASTODON_ACCESS_TOKEN")
MASTODON_API_URL = "https://mastodon.cipherbliss.com/api/v1/statuses" # Replace with actual instance
# Read MASTODON_ACCESS_TOKEN from .env file
env_vars = read_env_file(".env")
if not env_vars and os.path.exists(os.path.join(os.path.dirname(__file__), ".env")):
# Try with absolute path if relative path fails
env_vars = read_env_file(os.path.join(os.path.dirname(__file__), ".env"))
MASTODON_ACCESS_TOKEN = env_vars.get("MASTODON_ACCESS_TOKEN") or os.environ.get("MASTODON_ACCESS_TOKEN")
def load_outdated_pages():
"""
@ -126,7 +169,7 @@ def post_to_mastodon(post_text, dry_run=False):
return True
if not MASTODON_ACCESS_TOKEN:
logger.error("MASTODON_ACCESS_TOKEN environment variable not set")
logger.error("MASTODON_ACCESS_TOKEN not found in .env file or environment variables")
return False
headers = {