This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

update script

+25 -8
+2 -1
README.md
··· 91 91 - Authenticate using the AT Protocol. 92 92 - Update the Bluesky avatar accordingly. 93 93 94 - Execution logs will be displayed directly in the console, and a log file will be created in the `./logs/` directory. The log file will rotate when it reaches 10 MB, keeping up to 5 backup log files, each named with a timestamp for each execution. 94 + Execution logs will be displayed directly in the console, and a log file will be created in the `./logs/` directory. The log file will rotate every 14 days, keeping up to 5 backup log files. Logs older than 30 days will be automatically deleted. 95 95 96 96 ## Automating with Cron (Linux) 97 97 ··· 136 136 137 137 - **Endpoint not responding?** Verify that the Bluesky API endpoint is correct and accessible. 138 138 - **Cron job not running?** Verify that the cron job was properly set up using `crontab -l` or set it up manually. 139 + - **Old logs not deleting?** Ensure the script has the necessary permissions to delete files in the `./logs/` directory. 139 140 140 141 ## License 141 142
+23 -7
src/main.py
··· 9 9 from atproto.exceptions import BadRequestError 10 10 import sys 11 11 from crontab import CronTab 12 - from logging.handlers import RotatingFileHandler 12 + from logging.handlers import TimedRotatingFileHandler 13 + import glob 14 + import time 13 15 14 16 # Ensure the script is run inside a virtual environment 15 17 if not hasattr(sys, 'real_prefix') and not (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix): ··· 30 32 if not os.path.exists(log_dir): 31 33 os.makedirs(log_dir) 32 34 33 - # Log file with datetime stamp, but will be rotated 34 - log_file_path = os.path.join(log_dir, f"avatar_update_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log") 35 + def cleanup_old_logs(log_directory, days=30): 36 + """Deletes log files older than the specified number of days.""" 37 + cutoff = time.time() - (days * 86400) # Convert days to seconds 38 + for log_file in glob.glob(os.path.join(log_directory, "avatar_update*.log")): 39 + if os.path.isfile(log_file) and os.path.getmtime(log_file) < cutoff: 40 + os.remove(log_file) 41 + print(f"Deleted old log: {log_file}") 35 42 36 - # Configure logging to both console and file with rotation 43 + # Cleanup logs older than 30 days before setting up new logging 44 + cleanup_old_logs(log_dir, days=30) 45 + 46 + # Use a fixed log file name for the current log; TimedRotatingFileHandler will manage rotations. 47 + log_file_path = os.path.join(log_dir, "avatar_update.log") 48 + 49 + # Configure logging to both console and file with bi-weekly rotation 37 50 console_handler = logging.StreamHandler() 38 51 console_handler.setLevel(logging.INFO) # Show only INFO and higher levels on console 39 52 40 - # Create a rotating file handler (max file size 10 MB, backup 5 old log files) 41 - file_handler = RotatingFileHandler( 42 - log_file_path, maxBytes=10 * 1024 * 1024, backupCount=5 53 + # Create a timed rotating file handler (rotate every 14 days, keep up to 5 backups) 54 + file_handler = TimedRotatingFileHandler( 55 + log_file_path, 56 + when="D", # 'D' stands for days 57 + interval=14, # Rotate every 14 days 58 + backupCount=5 43 59 ) 44 60 file_handler.setLevel(logging.INFO) # Save all logs to file 45 61