def get_event_timestamp()

in tools/asciidoc_to_fragments.py [0:0]


def get_event_timestamp(repository, event, number):
    token_path = ''.join([expanduser("~"), github_token_location])
    with open(token_path, 'r') as f:
        token = f.read().rstrip()

    owner, repo = repository.split("/")[-2:]
    event_url = f"{owner}/{repo}/{event}/{number}"
    url = f"{api_url}{event_url}"
    headers = {"Accept": "application/vnd.github+json", "Authorization": f"Bearer {token}"}
    response = requests.get(url, headers=headers)
    data = response.json()

    if response.status_code == 404:
        return "not_found"
    elif data["closed_at"] is None:
        return "event_open"
    else:
        date = datetime.fromisoformat(data["closed_at"].replace('Z', '+00:00'))
        return str(int(datetime.timestamp(date)))