49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
|
|
from datetime import datetime, UTC
|
||
|
|
|
||
|
|
|
||
|
|
class CQLBuilder:
|
||
|
|
@staticmethod
|
||
|
|
def comment_poll(
|
||
|
|
since_iso: str,
|
||
|
|
space_keys: list[str] | None = None,
|
||
|
|
) -> str:
|
||
|
|
parts = ['type = "comment"']
|
||
|
|
if space_keys:
|
||
|
|
space_clause = " OR ".join(f'space = "{sk}"' for sk in space_keys)
|
||
|
|
parts.append(f"({space_clause})")
|
||
|
|
parts.append(f'lastModified > "{since_iso}"')
|
||
|
|
parts.append("ORDER BY lastModified ASC")
|
||
|
|
return " AND ".join(parts)
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def search_pages(
|
||
|
|
query: str,
|
||
|
|
space_keys: list[str] | None = None,
|
||
|
|
) -> str:
|
||
|
|
parts = [
|
||
|
|
f'(title ~ "{query}" OR text ~ "{query}")',
|
||
|
|
'type = "page"',
|
||
|
|
]
|
||
|
|
if space_keys:
|
||
|
|
space_clause = " OR ".join(f'space = "{sk}"' for sk in space_keys)
|
||
|
|
parts.append(f"({space_clause})")
|
||
|
|
return " AND ".join(parts)
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def recent_pages(
|
||
|
|
space_keys: list[str] | None = None,
|
||
|
|
hours: int = 24,
|
||
|
|
) -> str:
|
||
|
|
parts = [
|
||
|
|
'type = "page"',
|
||
|
|
f'lastModified > now("-{hours}h")',
|
||
|
|
]
|
||
|
|
if space_keys:
|
||
|
|
space_clause = " OR ".join(f'space = "{sk}"' for sk in space_keys)
|
||
|
|
parts.append(f"({space_clause})")
|
||
|
|
return " AND ".join(parts)
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def format_timestamp(ts: float) -> str:
|
||
|
|
return datetime.fromtimestamp(ts, tz=UTC).strftime("%Y-%m-%dT%H:%M:%S.000Z")
|