test weekly twet
This commit is contained in:
+40
-7
@@ -6,8 +6,40 @@ import random
|
||||
from openai import OpenAI # Add this import
|
||||
from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
# Logging configuration
|
||||
LOG_FILE = "/home/shane/foodie_automator/foodie_weekly_thread.log"
|
||||
LOG_PRUNE_DAYS = 30
|
||||
|
||||
def setup_logging():
|
||||
# Prune old logs
|
||||
if os.path.exists(LOG_FILE):
|
||||
with open(LOG_FILE, 'r') as f:
|
||||
lines = f.readlines()
|
||||
cutoff = datetime.now(timezone.utc) - timedelta(days=LOG_PRUNE_DAYS)
|
||||
pruned_lines = []
|
||||
for line in lines:
|
||||
try:
|
||||
timestamp = datetime.strptime(line[:19], '%Y-%m-%d %H:%M:%S').replace(tzinfo=timezone.utc)
|
||||
if timestamp > cutoff:
|
||||
pruned_lines.append(line)
|
||||
except ValueError:
|
||||
continue
|
||||
with open(LOG_FILE, 'w') as f:
|
||||
f.writelines(pruned_lines)
|
||||
|
||||
# Set up logging to file and console
|
||||
logging.basicConfig(
|
||||
filename=LOG_FILE,
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
||||
logging.getLogger().addHandler(console_handler)
|
||||
logging.info("Logging initialized for foodie_weekly_thread.py")
|
||||
|
||||
setup_logging()
|
||||
|
||||
# Initialize OpenAI client
|
||||
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
||||
@@ -131,8 +163,9 @@ def post_weekly_thread():
|
||||
logging.info(f"Successfully posted weekly thread for {author['username']}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Run only on Sundays
|
||||
if datetime.now(timezone.utc).weekday() == 6: # Sunday (0 = Monday, 6 = Sunday)
|
||||
post_weekly_thread()
|
||||
else:
|
||||
logging.info("Not Sunday - skipping weekly thread posting")
|
||||
print("Starting foodie_weekly_thread.py for testing")
|
||||
logging.info("Starting foodie_weekly_thread.py for testing")
|
||||
# Temporarily bypass Sunday check for testing
|
||||
post_weekly_thread()
|
||||
print("Completed foodie_weekly_thread.py test run")
|
||||
logging.info("Completed foodie_weekly_thread.py test run")
|
||||
Reference in New Issue
Block a user