Skip to content

Commit 1825207

Browse files
committed
Fixed bug on dashboard
1 parent 0b4d79a commit 1825207

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

content/folder/folder_content.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,25 @@ def get_remaining_post_count(self, days_ago = 180) -> int:
110110
count = self.db.run_query(query)
111111
return count[0] if count else 0
112112

113-
def get_oldest_last_posted(self) -> str | None:
113+
def get_oldest_last_posted(self) -> int | None:
114114
"""
115115
Returns the oldest last_posted date from the database.
116116
"""
117-
query = "SELECT TOP 1 c.last_posted FROM c ORDER BY c.last_posted ASC"
117+
query = "SELECT TOP 1 c.last_posted FROM c WHERE IS_DEFINED(c.last_posted) ORDER BY c.last_posted ASC"
118118
items = self.db.run_query(query)
119119

120120
if items:
121-
return items[0]["last_posted"]
121+
earliest = items[0]["last_posted"]
122122
else:
123123
return None
124+
125+
if earliest:
126+
# how many days ago was this date from today
127+
earliest = datetime.fromisoformat(earliest.replace("Z", "+00:00"))
128+
earliest = earliest.astimezone(timezone.utc)
129+
days_ago = (datetime.now(timezone.utc) - earliest).days
130+
return days_ago
131+
124132

125133
def queue_post(
126134
self,
@@ -179,4 +187,4 @@ def sync_last_posted():
179187
days = folder_content.get_remaining_post_count(days_ago=180)
180188
earliest = folder_content.get_oldest_last_posted()
181189
logger.debug(f"Remaining posts: {days}")
182-
logger.debug(f"Earliest last_posted: {earliest}")
190+
logger.debug(f"Earliest post was: {earliest}")

0 commit comments

Comments
 (0)