Since UTC

Persistent timestamp API beta

Unique RESTful endpoint to easily get/set a timestamp. Useful for bots, automation scripts and ephemeral processes. Often all your tool needs to know is the last time it ran but maintaining state adds a lot of code for one variable.

Each endpoint keeps one UNIX epoch timestamp in seconds as a float that can be get and set as JSON with an API key.

curl -X PUT -H "X-API-Key: 1234" example-endpoint-name/1673667454.395
⤷  {"utc_timestamp": 1673667454.395, "message": null}

curl -X PUT -H "X-API-Key: 1234" example-endpoint-name/now
⤷  {"utc_timestamp": , "message": null}

curl -H "X-API-Key: 1234" example-endpoint-name/
⤷  {"utc_timestamp": , "message": null}
Randomly generated endpoint name:
API Key:
CAPTCHA

Usage

Getting returns JSON dictionary that has two elements 'utc_timestamp' a float and 'message' a user readable string. Either could be null depending on status code.

API key is passed as a HTTP header with the name X-API-Key

Return status codes are 200 on OK, 404 if endpoint isn't known, 401 on bad API key, 406 if the request isn't well formed, 500 server error.

API keys can't be changed or recovered

Endpoint that hasn't been updated in 7 days will be deleted. Endpoint that doesn't get updated within a day of claiming will be deleted.

SinceUTC is free and no tracking is done beyond standard web server logging. Logs are rotated monthly.


# Set a timestamp
curl -X POST -H "X-API-Key: 1234" https://sinceutc.com/example-endpoint-name/1673576962.0

{
"message": null,
"utc_timestamp": 1673576962.0
}


# Get a timestamp
curl -H "X-API-Key: 1234" -H "Accept: application/json" https://sinceutc.com/example-endpoint-name/

{
"message": null,
"utc_timestamp": 1673667785.992466
}

# Set a timestamp with the keyword 'now' to set the current time on the server
curl -X POST -H "X-API-Key: 1234" https://sinceutc.com/example-endpoint-name/now

{
"message": null,
"utc_timestamp": 1673667790.01
}

# Example of a bad API key
curl -X POST -H "X-API-Key: crap" https://sinceutc.com/example-endpoint-name/now

{
"message": "bad or no X-API-Key",
"utc_timestamp": null
}
import sys
import logging
import os
import datetime
import time

import requests

bearer_token = os.environ.get("BEARER_TOKEN")
sinceutc_endpoint_name = os.environ.get("SINCEUTC_ENDPOINT_NAME")
sinceutc_endpoint_api_key = os.environ.get("SINCEUTC_ENDPOINT_APIKEY")

sinceutc_response = requests.get(f"https://{sinceutc_endpoint_name}.sinceutc.com",
                                 headers={"X-API-Key": sinceutc_endpoint_api_key,
                                          "Accept": "application/json"}
                                 )
if sinceutc_response.status_code != 200:
    logging.error(f"Since UTC call returned HTTPS status {sinceutc_response.status_code}. Expected 200. Bailing")
    sys.exit(-1)

# Format the sinceutc timestamp value the way Twitter wants it, as an ISO8601
since_time_iso8601 = datetime.datetime.utcfromtimestamp(sinceutc_response.json()['utc_timestamp']).isoformat()
logging.info(f"Last time script ran {since_time_iso8601}")

# Pass the timestamp as when to get the Tweets from
twitter_response = requests.get("https://api.twitter.com/2/tweets/search/recent",
                                auth={"Authorization": f"Bearer {bearer_token}",
                                      "User-Agent": "v2RecentSearchPython"},
                                params={"start_time": since_time_iso8601,
                                        "query": "from:twitterdev"}
                                )
# Do whatever

# Update the timestamp to now
sinceutc_update_response = requests.put(f"https://{sinceutc_endpoint_name}.sinceutc.com/{time.time()}",
                                        headers={"X-API-Key": sinceutc_endpoint_api_key}
                                        )
if sinceutc_update_response.status_code != 200:
    logging.error(
        f"Could not set timestamp. Since UTC returned HTTPS status {sinceutc_update_response.status_code}. Expected 200. Bailing")
    sys.exit(-1)

sys.exit(0)
        

Credits