neb/tools/statistics/get-monthly-cost.py

23 lines
611 B
Python
Raw Normal View History

#!/bin/python3.11
try:
from hcloud import Client
except ModuleNotFoundError:
print("please install hcloud module")
exit(1)
import os
client = Client(token=os.environ.get("HCLOUD_TOKEN"))
price = 0
for server in client.servers.get_all():
for pricing in server.server_type.prices:
if pricing['location'] == server.datacenter.location.name:
price += float(pricing['price_monthly']['gross'])
if server.public_net.primary_ipv4 is not None:
price += .61 # this is the gross amount pulled from the console at Oct 29th 16:57.
print(f"~{price} EUR")