Skip to content

Instantly share code, notes, and snippets.

@chuckmeyer
Last active January 21, 2022 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckmeyer/f0e657242f82bb669e045492cd9b4a18 to your computer and use it in GitHub Desktop.
Save chuckmeyer/f0e657242f82bb669e045492cd9b4a18 to your computer and use it in GitHub Desktop.
Get last update date for an Algolia index
#!python3
import dateutil.parser
from datetime import datetime, timezone
import os
from algoliasearch.search_client import SearchClient
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
INDEX_NAME = "address-geo"
client = SearchClient.create(os.getenv("APP_ID"), os.getenv("API_KEY"))
indices = client.list_indices()
updated_at = [
index["updatedAt"] for index in indices["items"] if index["name"] == INDEX_NAME
][0]
updated_date = dateutil.parser.isoparse(updated_at)
print(f'Index {INDEX_NAME} last update: {updated_date.strftime("%Y-%m-%d %H:%M:%S")}')
now = datetime.now(timezone.utc)
print(f'Current date and time: {now.strftime("%Y-%m-%d %H:%M:%S")}')
print(f"Last update was {now - updated_date} ago")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment