Updated open API Syntax
This commit is contained in:
@@ -2,12 +2,15 @@ import json
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
import random
|
||||
import openai
|
||||
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')
|
||||
|
||||
# Initialize OpenAI client
|
||||
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
||||
|
||||
RECENT_POSTS_FILE = "/home/shane/foodie_automator/recent_posts.json"
|
||||
|
||||
def load_recent_posts():
|
||||
@@ -45,7 +48,7 @@ def generate_intro_tweet(author):
|
||||
)
|
||||
|
||||
try:
|
||||
response = openai.ChatCompletion.create(
|
||||
response = client.chat.completions.create(
|
||||
model=SUMMARY_MODEL,
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a social media expert crafting engaging tweets."},
|
||||
@@ -82,7 +85,7 @@ def post_weekly_thread():
|
||||
# Group posts by author
|
||||
posts_by_author = {}
|
||||
for post in weekly_posts:
|
||||
author = post["author"]
|
||||
author = post["author_username"] # Updated to match the key in recent_posts.json
|
||||
if author not in posts_by_author:
|
||||
posts_by_author[author] = []
|
||||
posts_by_author[author].append(post)
|
||||
@@ -94,8 +97,8 @@ def post_weekly_thread():
|
||||
logging.info(f"No posts found for {author['username']} this week")
|
||||
continue
|
||||
|
||||
# Sort by interest score and take top 10
|
||||
author_posts.sort(key=lambda x: x.get("interest_score", 0), reverse=True)
|
||||
# Sort by timestamp (as a proxy for interest_score) and take top 10
|
||||
author_posts.sort(key=lambda x: x.get("timestamp", ""), reverse=True)
|
||||
top_posts = author_posts[:10]
|
||||
|
||||
if not top_posts:
|
||||
|
||||
Reference in New Issue
Block a user