You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howto-api-image-export.md
+39-28Lines changed: 39 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,35 +1,39 @@
1
-
You can use the XDMoD API to image export your saved metric explorer charts. A local XDMoD account is **required** to authenticate through the API.
2
-
3
-
The following Python script will export your saved metric explorer charts. The `dotenv` and `requests` libraries are used when authenticating through the XDMoD API. You can install these libraries through:
4
-
5
-
```shell
6
-
pip install python-dotenv
7
-
pip install requests
8
-
```
9
-
1
+
The following Python script will export your saved Metric Explorer charts. An XDMoD username and password is required to run the script.
10
2
Before running the script,
11
-
12
-
1. Install the required dependencies listed above.
13
-
1. Create a `.env` file with your local XDMoD account credentials in the same directory as the script.
14
-
1. Update `site_address` within the script with site address associated with your XDMoD instance.
3
+
1. Install the required `python-dotenv` and `requests` dependencies.
4
+
1. Create a `.env` file in the same directory as the script that contains the following contents, replacing `<username>` with your XDMoD username and `<password>` with your XDMoD password — make sure to secure this file with read-only access.
5
+
```
6
+
XDMOD_USERNAME=<username>
7
+
XDMOD_PASSWORD=<password>
8
+
```
9
+
1. Update the value of `site_address` within the script with the URL associated with your XDMoD portal.
10
+
1. Update the value of `export_path` within the script with the desired path to export the images.
15
11
1. Confirm the `image_format` within the script.
16
12
17
-
The script will export your saved metric explorer charts to the current working directory. **\*Note:** Replace `<XDMOD_URL_HERE>` with your site address.
13
+
The default image format is `svg`, but `png` and `pdf` formats are also supported. Refer to the XDMoD [Metric Explorer Tab Controller API](rest.html#tag/Metric-Explorer/paths/~1controllers~1metric_explorer.php/post) `get_data` operation for more information on the request body schema.
18
14
19
15
```python
20
16
#!/usr/bin/env python3
21
17
import os
22
18
import requests
23
19
import json
24
20
import urllib
21
+
import argparse
25
22
from dotenv import load_dotenv
26
23
27
-
load_dotenv()
24
+
site_address = ''
25
+
export_path = ''
26
+
image_format = 'svg'
27
+
image_width = 916
28
+
image_height = 484
28
29
30
+
load_dotenv()
29
31
username = os.getenv('XDMOD_USERNAME')
30
32
password = os.getenv('XDMOD_PASSWORD')
31
-
site_address ="<XDMOD_URL_HERE>"
32
-
image_format ="svg"
33
+
34
+
parser = argparse.ArgumentParser(description='Export XDMoD saved Metric Explorer charts with the REST API.')
35
+
parser.add_argument('-n', '--name',type=str, default='', help='Specify the chart name of a saved chart to export.')
36
+
args = parser.parse_args()
33
37
34
38
session = requests.Session()
35
39
@@ -42,14 +46,18 @@ if auth_response.status_code != 200:
chart_name = f"{chart['name']}.{image_format}" if ('name' in chart) else f"xdmod_API_export_{idx}.{image_format}"
77
85
78
-
withopen(chart_name, "wb") as f:
79
-
f.write(chart_response.content)
86
+
if args.name != '' and args.name == chart['name']:
87
+
with open(export_path + chart_name, "wb") as f:
88
+
f.write(chart_response.content)
89
+
exit()
90
+
else:
91
+
with open(export_path + chart_name, "wb") as f:
92
+
f.write(chart_response.content)
80
93
```
81
-
82
-
The default image format is `svg`, but `png` and `pdf` formats are also supported. Refer to the XDMoD [Metric Explorer Tab Controller API](rest.html#tag/Metric-Explorer/paths/~1controllers~1metric_explorer.php/post)`get_data` operation for more information on the request body schema.
0 commit comments