Created
October 30, 2019 22:40
-
-
Save rhizoome/5b92d4a5414d63eb1ec3e363c5996845 to your computer and use it in GitHub Desktop.
azure subscription cost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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