Skip to content

Instantly share code, notes, and snippets.

@rhizoome
Created October 30, 2019 22:40
Show Gist options
  • Save rhizoome/5b92d4a5414d63eb1ec3e363c5996845 to your computer and use it in GitHub Desktop.
Save rhizoome/5b92d4a5414d63eb1ec3e363c5996845 to your computer and use it in GitHub Desktop.
azure subscription cost
import datetime
import json
from subprocess import check_output
end = datetime.datetime.now() + datetime.timedelta(days=1)
start = end - datetime.timedelta(days=31)
end_fmt = end.strftime("%Y-%m-%d")
start_fmt = start.strftime("%Y-%m-%d")
cmd = (
"az consumption usage list --output json --subscription REPLACE_WITH_SUBSCRIPTION"
).split(" ")
data = check_output(cmd + ["-s", start_fmt, "-e", end_fmt])
cost = json.loads(data)
sum = 0
for i in cost:
sum += float(i["pretaxCost"])
print("30 day cost: %.2f EUR" % sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment