use correct columns

This commit is contained in:
Stefan Bethke 2024-05-18 21:05:00 +02:00
parent 7c4cb94ea8
commit 9bc4278c82
2 changed files with 5 additions and 2 deletions

View file

View file

@ -90,6 +90,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]:
""" """
revisions = [] revisions = []
with db.prepare('''SELECT with db.prepare('''SELECT
"Notes"."alias",
"Revisions"."createdAt", "Revisions"."createdAt",
"Users"."email", "Users"."email",
"Revisions"."id" as "revisionId", "Revisions"."id" as "revisionId",
@ -103,6 +104,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]:
''') as revs_older_than: ''') as revs_older_than:
for row in revs_older_than(cutoff): for row in revs_older_than(cutoff):
revisions.append({ revisions.append({
'alias': row.alias,
'createdAt': row.createdAt, 'createdAt': row.createdAt,
'email': row.email, 'email': row.email,
'noteId': row.noteId, 'noteId': row.noteId,
@ -118,7 +120,8 @@ def check_notes_to_be_expired(age: timedelta, config: Config) -> None:
print(f'Notes to be deleted older than {cutoff} ({humanize.naturaldelta(age)}):') print(f'Notes to be deleted older than {cutoff} ({humanize.naturaldelta(age)}):')
for note in notes_to_be_expired(cutoff): for note in notes_to_be_expired(cutoff):
age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt']) age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt'])
print(f' {note["email"]} ({humanize.naturaldelta(age)}) {config.url}/{note["alias"]}: {note["title"]}') url = config.url + '/' + (note["alias"] if note["alias"] is not None else note["shortid"])
print(f' {note["email"]} ({humanize.naturaldelta(age)}) {url}: {note["title"]}')
def check_revisions_to_be_expired(age: timedelta, config: Config) -> None: def check_revisions_to_be_expired(age: timedelta, config: Config) -> None:
@ -132,7 +135,7 @@ def check_revisions_to_be_expired(age: timedelta, config: Config) -> None:
notes[row['noteId']].append(row) notes[row['noteId']].append(row)
for id, revisions in notes.items(): for id, revisions in notes.items():
email = revisions[0]['email'] email = revisions[0]['email']
url = config.url + '/' + (revisions[0]["title"] if revisions[0]["title"] is not None else revisions[0]["shorturl"]) url = config.url + '/' + (revisions[0]["alias"] if revisions[0]["alias"] is not None else revisions[0]["shortid"])
print(f' {revisions[0]["email"]} {url}: {revisions[0]["title"]}') print(f' {revisions[0]["email"]} {url}: {revisions[0]["title"]}')
for rev in revisions: for rev in revisions:
print(f' {humanize.naturaldelta(rev["age"])}: {rev["revisionId"]}') print(f' {humanize.naturaldelta(rev["age"])}: {rev["revisionId"]}')