# Span Participation

The script retrieves information about the latest span, prompts the user for a validator ID, and checks if that validator is currently participating in the span. These operations aid in monitoring the involvement of a validator.

```bash
import os
import requests

if os.path.exists("lockfile"):
    exit()

with open("lockfile", "w") as file:
    file.write("")

def get_current_span_id():
    try:
        url = "https://heimdall-api.polygon.technology/bor/latest-span"
        response = requests.get(url)
        if response.status_code == 200:
            data = response.json()
            span_id = data.get("result", {}).get("span_id")
            return span_id
        else:
            return None
    except Exception as e:
        return None

def check_validator_in_current_span(span_id, validator_id):
    try:
        url = f"https://heimdall-api.polygon.technology/bor/span/{span_id}"
        response = requests.get(url)
        if response.status_code == 200:
            data = response.json()
            selected_producers = data.get("result", {}).get("validator_set", {}).get("validators", [])
            for validator in selected_producers:
                if validator["ID"] == validator_id:
                    return "The validator is part of the current span."
            return "The validator is NOT part of the current span."
        else:
            return "Error fetching current span information."
    except Exception as e:
        return "Error checking validator in the current span."

if __name__ == "__main__":
    validator_id = int(input("Enter the validator ID: "))
    current_span_id = get_current_span_id()

    if current_span_id is not None:
        response = check_validator_in_current_span(current_span_id, validator_id)
        print(response)

    
    os.remove("lockfile")
```

Python and Requests Installation:

Make sure you have Python installed on your system. Open the terminal or command prompt. Execute the following command to install the `requests` library:

```bash
pip install requests
```

Script Execution:

Save the Python script (`Your_script.py`) in the directory of your choice. Place a file named "addresses.txt" in the same directory as the script, containing the addresses of the validators.

Run the Script:

In the terminal or command prompt, navigate to the directory where the script is located. Execute the script using the following command:

```bash
python3 your_script.py
```

Results:

The script checks if the validator with the provided ID is among the validators of the current span.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stakepool.dev.br/polygon/scripts/span-participation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
