#!/usr/bin/env python3 #! /usr/bin/env python3 import os import re import sys import yaml from datetime import datetime from jinja2 import Template # Define the template for the HTML file html_template = """ Attestation Data

About

See the TXOO repo for more information.

Generated at {{ now }}

Oracle Configuration

network: {{ config["network"] }}

start_block: {{ config["start_block"] }}

public_key: {{ config["public_key"] }}

Attestation Data

{% for row in rows %} {% endfor %}
Block Hash Block Height Filter Header Timestamp
{{ row['block_hash'] }} {{ row['block_height'] }} {{ row['filter_header'] }} {{ row['time'] }} Explorer
""" def process_file(file_path): with open(file_path, "r") as f: data = yaml.safe_load(f) # Convert the Unix timestamp in the "time" field to a datetime object in ISO format data = data["attestation"] timestamp = int(data["time"]) data["time"] = datetime.utcfromtimestamp(timestamp).isoformat(sep=" ", timespec="seconds") return data def main(dir_path): output_file_path = os.path.join(dir_path, "index.html") file_pattern = re.compile(r"\d+-[0-9a-f]+\.sa$") rows = [] with open(os.path.join(dir_path, "config"), "r") as f: config = yaml.safe_load(f) # filter and sort the files files = [f for f in os.listdir(dir_path) if file_pattern.match(f)] files.sort(key=lambda f: int(f.split("-")[0]), reverse=True) for file_name in files: if file_pattern.match(file_name): file_path = os.path.join(dir_path, file_name) row = process_file(file_path) row['filename'] = file_name rows.append(row) now = datetime.now().isoformat(sep=" ", timespec="seconds") if rows: template = Template(html_template) html_content = template.render(rows=rows, config=config, now=now) with open(output_file_path, "w") as f: f.write(html_content) else: print("No matching files found.") if __name__ == "__main__": main(sys.argv[1])