Shreyas094 commited on
Commit
6e829a6
·
verified ·
1 Parent(s): 5871ec6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -25
app.py CHANGED
@@ -9,32 +9,38 @@ load_dotenv()
9
  # Replace with your actual Cloudflare API token
10
  API_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
11
 
12
- # Cloudflare API endpoint for getting account details
13
- url = "https://api.cloudflare.com/client/v4/accounts"
14
-
15
- # Headers for the API request
16
- headers = {
17
- "Authorization": f"Bearer {API_TOKEN}",
18
- "Content-Type": "application/json"
19
- }
20
-
21
- # Making the API request
22
- response = requests.get(url, headers=headers)
23
-
24
- # Checking if the request was successful
25
- if response.status_code == 200:
26
- # Parsing the JSON response
27
- data = response.json()
28
- if data['success']:
29
- accounts = data['result']
30
- for account in accounts:
31
- account_id = account['id']
32
- account_name = account['name']
33
- print(f"Account Name: {account_name}, Account ID: {account_id}")
 
 
 
 
 
 
 
 
34
  else:
35
- print("Error fetching account details:", data['errors'])
36
- else:
37
- print("Failed to fetch account details. HTTP Status Code:", response.status_code)
38
 
39
  # Creating a Gradio interface
40
  iface = gr.Interface(fn=get_cloudflare_accounts,
 
9
  # Replace with your actual Cloudflare API token
10
  API_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
11
 
12
+ def get_cloudflare_accounts():
13
+ if not API_TOKEN:
14
+ return "Please set the CLOUDFLARE_API_TOKEN environment variable"
15
+
16
+ # Cloudflare API endpoint for getting account details
17
+ url = "https://api.cloudflare.com/client/v4/accounts"
18
+
19
+ # Headers for the API request
20
+ headers = {
21
+ "Authorization": f"Bearer {API_TOKEN}",
22
+ "Content-Type": "application/json"
23
+ }
24
+
25
+ # Making the API request
26
+ response = requests.get(url, headers=headers)
27
+
28
+ # Checking if the request was successful
29
+ if response.status_code == 200:
30
+ # Parsing the JSON response
31
+ data = response.json()
32
+ if data['success']:
33
+ accounts = data['result']
34
+ result = ""
35
+ for account in accounts:
36
+ account_id = account['id']
37
+ account_name = account['name']
38
+ result += f"Account Name: {account_name}, Account ID: {account_id}\n"
39
+ return result
40
+ else:
41
+ return f"Error fetching account details: {data['errors']}"
42
  else:
43
+ return f"Failed to fetch account details. HTTP Status Code: {response.status_code}"
 
 
44
 
45
  # Creating a Gradio interface
46
  iface = gr.Interface(fn=get_cloudflare_accounts,