mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-04-28 19:23:41 +01:00
last 7 prompts not 7 days
This commit is contained in:
parent
30d25d1d7a
commit
c4b9dd2921
12
lib.py
12
lib.py
@ -17,7 +17,7 @@ from tenacity import (
|
|||||||
)
|
)
|
||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
|
|
||||||
nest_asyncio.apply()
|
nest_asyncio.apply()
|
||||||
|
|
||||||
@ -26,17 +26,15 @@ logging.basicConfig(level=logging.INFO)
|
|||||||
LOG_FILE = "./prompts_log.jsonl"
|
LOG_FILE = "./prompts_log.jsonl"
|
||||||
|
|
||||||
|
|
||||||
def load_recent_prompts(days=7):
|
def load_recent_prompts(count=7):
|
||||||
recent_prompts = []
|
recent_prompts = []
|
||||||
cutoff_date = datetime.now().date() - timedelta(days=days)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(LOG_FILE, "r") as f:
|
with open(LOG_FILE, "r") as f:
|
||||||
for line in f:
|
lines = f.readlines()
|
||||||
|
for line in lines[-count:]:
|
||||||
data = json.loads(line.strip())
|
data = json.loads(line.strip())
|
||||||
prompt_date = datetime.strptime(data["date"], "%Y-%m-%d").date()
|
recent_prompts.append(data["prompt"])
|
||||||
if prompt_date >= cutoff_date:
|
|
||||||
recent_prompts.append(data["prompt"])
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass # No prompts yet
|
pass # No prompts yet
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user