update username X
This commit is contained in:
+14
-20
@@ -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": {
|
||||||
|
|||||||
+46
-30
@@ -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 = []
|
|
||||||
cutoff = datetime.now(timezone.utc) - timedelta(hours=expiration_hours)
|
|
||||||
|
|
||||||
if not os.path.exists(file_path):
|
|
||||||
logging.info(f"File {file_path} does not exist, returning empty list")
|
|
||||||
return entries
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
logging.info(f"File {file_path} does not exist, initializing with empty list")
|
||||||
|
with open(file_path, 'w') as f:
|
||||||
|
json.dump([], f)
|
||||||
|
return []
|
||||||
|
|
||||||
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:
|
|
||||||
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']}")
|
|
||||||
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"Invalid JSON in {file_path}: {e}. Attempting line-by-line parsing.")
|
||||||
continue
|
data = []
|
||||||
except Exception as e:
|
f.seek(0)
|
||||||
logging.warning(f"Skipping malformed entry in {file_path} at line {i}: {line.strip()}")
|
for line_number, line in enumerate(f, 1):
|
||||||
continue
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
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")
|
if not isinstance(data, list):
|
||||||
return entries
|
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:
|
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user