-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaleway.py
More file actions
45 lines (38 loc) · 1.44 KB
/
scaleway.py
File metadata and controls
45 lines (38 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import datetime
import calendar
import requests
def scaleway(access_key, secret_key, item_number, proxy):
# cURL example
# curl -X GET -H "X-Auth-Token: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" "https://api.scaleway.com/billing/v2beta1/invoices"
url = "https://api.scaleway.com/billing/v2beta1/invoices"
headers = {
"X-Auth-Token": secret_key,
"Content-Type": "application/json"
}
if proxy is not None:
proxy = {
"http": proxy["server"],
"https": proxy["server"]
}
else:
proxy = None
print("Using proxy:", proxy)
response = requests.get(url, headers=headers, proxies=proxy)
# If response.status_code is not 200, raise an exception
if response.status_code != 200:
raise Exception(f"Error: {response.status_code} - {response.text}")
invoices = response.json().get("invoices")
organisation_name = invoices[0]["organization_name"]
# Get the due date
due_date = invoices[0]["due_date"]
# Convert the due date to a datetime object
due_date = datetime.datetime.strptime(due_date, "%Y-%m-%dT%H:%M:%S.%fZ")
# Get the current date
current_date = datetime.datetime.now()
# Calculate the difference in days
days_remaining = (due_date - current_date).days
if invoices[0]["state"] != "paid":
payment_status = False
else:
payment_status = True
return organisation_name, days_remaining, payment_status