update username X
This commit is contained in:
+14
-20
@@ -60,62 +60,56 @@ AUTHORS = [
|
||||
}
|
||||
]
|
||||
|
||||
X_API_CREDENTIALS = [
|
||||
{
|
||||
"username": "owenjohnson",
|
||||
"x_username": "@insiderfoodieowen",
|
||||
X_API_CREDENTIALS = {
|
||||
"owenjohnson": {
|
||||
"x_username": "@mrowenjohnson",
|
||||
"api_key": os.getenv("OWENJOHNSON_X_API_KEY"),
|
||||
"api_secret": os.getenv("OWENJOHNSON_X_API_SECRET"),
|
||||
"access_token": os.getenv("OWENJOHNSON_X_ACCESS_TOKEN"),
|
||||
"access_token_secret": os.getenv("OWENJOHNSON_X_ACCESS_TOKEN_SECRET"),
|
||||
"client_secret": os.getenv("OWENJOHNSON_X_CLIENT_SECRET")
|
||||
},
|
||||
{
|
||||
"username": "javiermorales",
|
||||
"x_username": "@insiderfoodiejavier",
|
||||
"javiermorales": {
|
||||
"x_username": "@mrjaviermorales",
|
||||
"api_key": os.getenv("JAVIERMORALES_X_API_KEY"),
|
||||
"api_secret": os.getenv("JAVIERMORALES_X_API_SECRET"),
|
||||
"access_token": os.getenv("JAVIERMORALES_X_ACCESS_TOKEN"),
|
||||
"access_token_secret": os.getenv("JAVIERMORALES_X_ACCESS_TOKEN_SECRET"),
|
||||
"client_secret": os.getenv("JAVIERMORALES_X_CLIENT_SECRET")
|
||||
},
|
||||
{
|
||||
"username": "aishapatel",
|
||||
"x_username": "@insiderfoodieaisha",
|
||||
"aishapatel": {
|
||||
"x_username": "@missaishapatel",
|
||||
"api_key": os.getenv("AISHAPATEL_X_API_KEY"),
|
||||
"api_secret": os.getenv("AISHAPATEL_X_API_SECRET"),
|
||||
"access_token": os.getenv("AISHAPATEL_X_ACCESS_TOKEN"),
|
||||
"access_token_secret": os.getenv("AISHAPATEL_X_ACCESS_TOKEN_SECRET"),
|
||||
"client_secret": os.getenv("AISHAPATEL_X_CLIENT_SECRET")
|
||||
},
|
||||
{
|
||||
"username": "trangnguyen",
|
||||
"x_username": "@insiderfoodietrang",
|
||||
"trangnguyen": {
|
||||
"x_username": "@mrtrangnguyen",
|
||||
"api_key": os.getenv("TRANGNGUYEN_X_API_KEY"),
|
||||
"api_secret": os.getenv("TRANGNGUYEN_X_API_SECRET"),
|
||||
"access_token": os.getenv("TRANGNGUYEN_X_ACCESS_TOKEN"),
|
||||
"access_token_secret": os.getenv("TRANGNGUYEN_X_ACCESS_TOKEN_SECRET"),
|
||||
"client_secret": os.getenv("TRANGNGUYEN_X_CLIENT_SECRET")
|
||||
},
|
||||
{
|
||||
"username": "keishareid",
|
||||
"x_username": "@insiderfoodiekeisha",
|
||||
"keishareid": {
|
||||
"x_username": "@misskeishareid",
|
||||
"api_key": os.getenv("KEISHAREID_X_API_KEY"),
|
||||
"api_secret": os.getenv("KEISHAREID_X_API_SECRET"),
|
||||
"access_token": os.getenv("KEISHAREID_X_ACCESS_TOKEN"),
|
||||
"access_token_secret": os.getenv("KEISHAREID_X_ACCESS_TOKEN_SECRET"),
|
||||
"client_secret": os.getenv("KEISHAREID_X_CLIENT_SECRET")
|
||||
},
|
||||
{
|
||||
"username": "lilamoreau",
|
||||
"x_username": "@insiderfoodielila",
|
||||
"lilamoreau": {
|
||||
"x_username": "@misslilamoreau",
|
||||
"api_key": os.getenv("LILAMOREAU_X_API_KEY"),
|
||||
"api_secret": os.getenv("LILAMOREAU_X_API_SECRET"),
|
||||
"access_token": os.getenv("LILAMOREAU_X_ACCESS_TOKEN"),
|
||||
"access_token_secret": os.getenv("LILAMOREAU_X_ACCESS_TOKEN_SECRET"),
|
||||
"client_secret": os.getenv("LILAMOREAU_X_CLIENT_SECRET")
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
PERSONA_CONFIGS = {
|
||||
"Visionary Editor": {
|
||||
|
||||
+43
-27
@@ -32,42 +32,58 @@ IMAGE_UPLOAD_TIMEOUT = 30 # Added to fix NameError
|
||||
|
||||
IMAGE_EXPIRATION_DAYS = 7 # 7 days, consistent with foodie_automator_rss.py
|
||||
|
||||
def load_json_file(file_path, expiration_hours):
|
||||
entries = []
|
||||
cutoff = datetime.now(timezone.utc) - timedelta(hours=expiration_hours)
|
||||
|
||||
def load_json_file(file_path, expiration_hours=None):
|
||||
try:
|
||||
if not os.path.exists(file_path):
|
||||
logging.info(f"File {file_path} does not exist, returning empty list")
|
||||
return entries
|
||||
logging.info(f"File {file_path} does not exist, initializing with empty list")
|
||||
with open(file_path, 'w') as f:
|
||||
json.dump([], f)
|
||||
return []
|
||||
|
||||
try:
|
||||
with open(file_path, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
for i, line in enumerate(lines, 1):
|
||||
try:
|
||||
entry = json.loads(line.strip())
|
||||
if not isinstance(entry, dict) or "title" not in entry or "timestamp" not in entry:
|
||||
logging.warning(f"Skipping malformed entry in {file_path} at line {i}: {line.strip()}")
|
||||
continue
|
||||
|
||||
timestamp = datetime.fromisoformat(entry["timestamp"])
|
||||
if timestamp > cutoff:
|
||||
entries.append(entry)
|
||||
else:
|
||||
logging.debug(f"Entry expired in {file_path}: {entry['title']}")
|
||||
data = json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
logging.warning(f"Skipping invalid JSON line in {file_path} at line {i}: {e}")
|
||||
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
|
||||
except Exception as e:
|
||||
logging.warning(f"Skipping malformed entry in {file_path} at line {i}: {line.strip()}")
|
||||
try:
|
||||
entry = json.loads(line)
|
||||
data.append(entry)
|
||||
except json.JSONDecodeError as e:
|
||||
logging.warning(f"Skipping invalid JSON line in {file_path} at line {line_number}: {e}")
|
||||
continue
|
||||
|
||||
logging.info(f"Loaded {len(entries)} entries from {file_path}, {len(entries)} valid after expiration check")
|
||||
return entries
|
||||
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
|
||||
else:
|
||||
valid_entries = data
|
||||
|
||||
logging.info(f"Loaded {len(valid_entries)} entries from {file_path}, {len(valid_entries)} valid after expiration check")
|
||||
return valid_entries
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to load {file_path}: {e}")
|
||||
return entries
|
||||
logging.error(f"Failed to load JSON file {file_path}: {e}")
|
||||
return []
|
||||
|
||||
def save_json_file(file_path, title, timestamp):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user