summaryrefslogtreecommitdiff
path: root/current_king.py
blob: 6bd06b7246a233a7d29a8e5d46605a73536a273e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
import urllib.request
import urllib.error

def get_king_data():
    """Request data from localhost king endpoint and return response body as string."""
    try:
        with urllib.request.urlopen("http://localhost:8080/api/v1/king") as response:
            return response.read().decode('utf-8')
    except urllib.error.URLError as e:
        raise Exception(f"Failed to fetch king data: {e}")

print(get_king_data())