update username X

main
Shane 7 months ago
parent f6ab7e78d3
commit 8825d7a9f8
  1. 34
      foodie_config.py
  2. 68
      foodie_utils.py

@ -60,62 +60,56 @@ AUTHORS = [
} }
] ]
X_API_CREDENTIALS = [ X_API_CREDENTIALS = {
{ "owenjohnson": {
"username": "owenjohnson", "x_username": "@mrowenjohnson",
"x_username": "@insiderfoodieowen",
"api_key": os.getenv("OWENJOHNSON_X_API_KEY"), "api_key": os.getenv("OWENJOHNSON_X_API_KEY"),
"api_secret": os.getenv("OWENJOHNSON_X_API_SECRET"), "api_secret": os.getenv("OWENJOHNSON_X_API_SECRET"),
"access_token": os.getenv("OWENJOHNSON_X_ACCESS_TOKEN"), "access_token": os.getenv("OWENJOHNSON_X_ACCESS_TOKEN"),
"access_token_secret": os.getenv("OWENJOHNSON_X_ACCESS_TOKEN_SECRET"), "access_token_secret": os.getenv("OWENJOHNSON_X_ACCESS_TOKEN_SECRET"),
"client_secret": os.getenv("OWENJOHNSON_X_CLIENT_SECRET") "client_secret": os.getenv("OWENJOHNSON_X_CLIENT_SECRET")
}, },
{ "javiermorales": {
"username": "javiermorales", "x_username": "@mrjaviermorales",
"x_username": "@insiderfoodiejavier",
"api_key": os.getenv("JAVIERMORALES_X_API_KEY"), "api_key": os.getenv("JAVIERMORALES_X_API_KEY"),
"api_secret": os.getenv("JAVIERMORALES_X_API_SECRET"), "api_secret": os.getenv("JAVIERMORALES_X_API_SECRET"),
"access_token": os.getenv("JAVIERMORALES_X_ACCESS_TOKEN"), "access_token": os.getenv("JAVIERMORALES_X_ACCESS_TOKEN"),
"access_token_secret": os.getenv("JAVIERMORALES_X_ACCESS_TOKEN_SECRET"), "access_token_secret": os.getenv("JAVIERMORALES_X_ACCESS_TOKEN_SECRET"),
"client_secret": os.getenv("JAVIERMORALES_X_CLIENT_SECRET") "client_secret": os.getenv("JAVIERMORALES_X_CLIENT_SECRET")
}, },
{ "aishapatel": {
"username": "aishapatel", "x_username": "@missaishapatel",
"x_username": "@insiderfoodieaisha",
"api_key": os.getenv("AISHAPATEL_X_API_KEY"), "api_key": os.getenv("AISHAPATEL_X_API_KEY"),
"api_secret": os.getenv("AISHAPATEL_X_API_SECRET"), "api_secret": os.getenv("AISHAPATEL_X_API_SECRET"),
"access_token": os.getenv("AISHAPATEL_X_ACCESS_TOKEN"), "access_token": os.getenv("AISHAPATEL_X_ACCESS_TOKEN"),
"access_token_secret": os.getenv("AISHAPATEL_X_ACCESS_TOKEN_SECRET"), "access_token_secret": os.getenv("AISHAPATEL_X_ACCESS_TOKEN_SECRET"),
"client_secret": os.getenv("AISHAPATEL_X_CLIENT_SECRET") "client_secret": os.getenv("AISHAPATEL_X_CLIENT_SECRET")
}, },
{ "trangnguyen": {
"username": "trangnguyen", "x_username": "@mrtrangnguyen",
"x_username": "@insiderfoodietrang",
"api_key": os.getenv("TRANGNGUYEN_X_API_KEY"), "api_key": os.getenv("TRANGNGUYEN_X_API_KEY"),
"api_secret": os.getenv("TRANGNGUYEN_X_API_SECRET"), "api_secret": os.getenv("TRANGNGUYEN_X_API_SECRET"),
"access_token": os.getenv("TRANGNGUYEN_X_ACCESS_TOKEN"), "access_token": os.getenv("TRANGNGUYEN_X_ACCESS_TOKEN"),
"access_token_secret": os.getenv("TRANGNGUYEN_X_ACCESS_TOKEN_SECRET"), "access_token_secret": os.getenv("TRANGNGUYEN_X_ACCESS_TOKEN_SECRET"),
"client_secret": os.getenv("TRANGNGUYEN_X_CLIENT_SECRET") "client_secret": os.getenv("TRANGNGUYEN_X_CLIENT_SECRET")
}, },
{ "keishareid": {
"username": "keishareid", "x_username": "@misskeishareid",
"x_username": "@insiderfoodiekeisha",
"api_key": os.getenv("KEISHAREID_X_API_KEY"), "api_key": os.getenv("KEISHAREID_X_API_KEY"),
"api_secret": os.getenv("KEISHAREID_X_API_SECRET"), "api_secret": os.getenv("KEISHAREID_X_API_SECRET"),
"access_token": os.getenv("KEISHAREID_X_ACCESS_TOKEN"), "access_token": os.getenv("KEISHAREID_X_ACCESS_TOKEN"),
"access_token_secret": os.getenv("KEISHAREID_X_ACCESS_TOKEN_SECRET"), "access_token_secret": os.getenv("KEISHAREID_X_ACCESS_TOKEN_SECRET"),
"client_secret": os.getenv("KEISHAREID_X_CLIENT_SECRET") "client_secret": os.getenv("KEISHAREID_X_CLIENT_SECRET")
}, },
{ "lilamoreau": {
"username": "lilamoreau", "x_username": "@misslilamoreau",
"x_username": "@insiderfoodielila",
"api_key": os.getenv("LILAMOREAU_X_API_KEY"), "api_key": os.getenv("LILAMOREAU_X_API_KEY"),
"api_secret": os.getenv("LILAMOREAU_X_API_SECRET"), "api_secret": os.getenv("LILAMOREAU_X_API_SECRET"),
"access_token": os.getenv("LILAMOREAU_X_ACCESS_TOKEN"), "access_token": os.getenv("LILAMOREAU_X_ACCESS_TOKEN"),
"access_token_secret": os.getenv("LILAMOREAU_X_ACCESS_TOKEN_SECRET"), "access_token_secret": os.getenv("LILAMOREAU_X_ACCESS_TOKEN_SECRET"),
"client_secret": os.getenv("LILAMOREAU_X_CLIENT_SECRET") "client_secret": os.getenv("LILAMOREAU_X_CLIENT_SECRET")
} }
] }
PERSONA_CONFIGS = { PERSONA_CONFIGS = {
"Visionary Editor": { "Visionary Editor": {

@ -32,42 +32,58 @@ IMAGE_UPLOAD_TIMEOUT = 30 # Added to fix NameError
IMAGE_EXPIRATION_DAYS = 7 # 7 days, consistent with foodie_automator_rss.py IMAGE_EXPIRATION_DAYS = 7 # 7 days, consistent with foodie_automator_rss.py
def load_json_file(file_path, expiration_hours): def load_json_file(file_path, expiration_hours=None):
entries = [] try:
cutoff = datetime.now(timezone.utc) - timedelta(hours=expiration_hours)
if not os.path.exists(file_path): if not os.path.exists(file_path):
logging.info(f"File {file_path} does not exist, returning empty list") logging.info(f"File {file_path} does not exist, initializing with empty list")
return entries with open(file_path, 'w') as f:
json.dump([], f)
return []
try:
with open(file_path, 'r') as f: with open(file_path, 'r') as f:
lines = f.readlines()
for i, line in enumerate(lines, 1):
try: try:
entry = json.loads(line.strip()) data = json.load(f)
if not isinstance(entry, dict) or "title" not in entry or "timestamp" not in entry: except json.JSONDecodeError as e:
logging.warning(f"Skipping malformed entry in {file_path} at line {i}: {line.strip()}") logging.warning(f"Invalid JSON in {file_path}: {e}. Attempting line-by-line parsing.")
data = []
f.seek(0)
for line_number, line in enumerate(f, 1):
line = line.strip()
if not line:
continue continue
try:
timestamp = datetime.fromisoformat(entry["timestamp"]) entry = json.loads(line)
if timestamp > cutoff: data.append(entry)
entries.append(entry)
else:
logging.debug(f"Entry expired in {file_path}: {entry['title']}")
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
logging.warning(f"Skipping invalid JSON line in {file_path} at line {i}: {e}") logging.warning(f"Skipping invalid JSON line in {file_path} at line {line_number}: {e}")
continue continue
except Exception as e:
logging.warning(f"Skipping malformed entry in {file_path} at line {i}: {line.strip()}") if not isinstance(data, list):
logging.warning(f"Data in {file_path} is not a list, resetting to empty list")
data = []
valid_entries = []
if expiration_hours:
cutoff = datetime.now(timezone.utc) - timedelta(hours=expiration_hours)
for entry in data:
try:
timestamp_str = entry.get("timestamp")
if timestamp_str:
timestamp = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
if timestamp < cutoff:
continue
valid_entries.append(entry)
except (ValueError, TypeError) as e:
logging.warning(f"Skipping malformed entry in {file_path}: {e}")
continue continue
else:
valid_entries = data
logging.info(f"Loaded {len(entries)} entries from {file_path}, {len(entries)} valid after expiration check") logging.info(f"Loaded {len(valid_entries)} entries from {file_path}, {len(valid_entries)} valid after expiration check")
return entries return valid_entries
except Exception as e: except Exception as e:
logging.error(f"Failed to load {file_path}: {e}") logging.error(f"Failed to load JSON file {file_path}: {e}")
return entries return []
def save_json_file(file_path, title, timestamp): def save_json_file(file_path, title, timestamp):
try: try:

Loading…
Cancel
Save