Skip to content

Instantly share code, notes, and snippets.

@yuwtennis
Last active December 29, 2022 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuwtennis/174d1e37b3c76e7050e8644e0ea516e5 to your computer and use it in GitHub Desktop.
Save yuwtennis/174d1e37b3c76e7050e8644e0ea516e5 to your computer and use it in GitHub Desktop.
SUBSCRIPTION_ID: str = os.environ.get("SUBSCRIPTION_ID", None)
SCOPE: str =f'/subscriptions/{SUBSCRIPTION_ID}'
logging.basicConfig(filename='./az-sdk-consumption-api-8-0-0-b1.log', level=logging.DEBUG, force=True)
current_timestamp = datetime.datetime.now(datetime.timezone.utc).strftime("%c %")
print(f"Querying Microsoft REST API. Started on {current_timestamp}")
consumption_client = ConsumptionManagementClient(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
result = consumption_client.usage_details.list(
SCOPE,
metric='AmortizedCost')
o = next(result)
attrs = [
'billing_period_end_date',
'billing_period_start_date',
'date',
'exchange_rate_date',
'service_period_end_date',
'service_period_start_date'
]
for attr in attrs:
print(f"{attr}: {getattr(o, attr)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment