#!/usr/bin/env python3
import requests
import configparser
from pathlib import Path
from tabulate import tabulate

config = configparser.ConfigParser()
config.read(Path().home() / "config")
# api_token = "api_token_from_htb_profile"
api_token = config["htb_api"]["api_token"]

s = requests.session()
s.headers = {'user-agent': 'api'}
base_url = "https://www.hackthebox.eu/api"

x = s.get(f"{base_url}/machines/get/all/?api_token={api_token}").json()

for element in x:
    for i in ["avatar_thumb", "maker", "free", "maker2"]:
        element.pop(i, None)

print(tabulate(x, tablefmt="fancy_grid", headers={field: field for field in x[0]}))
