Hey, all. My apologies as I'm new to python in general, so I'm doing a lot of reading that goes over my head. :)
I'm working on a multi-step process where I run one python script that makes an API call to a system. I then have to extract some of those values from that output so that I can submit them, along with a new password, via a second API call that I would make after.
I have two main questions, first, is it possible to pipe the output of the initial API call directly to a text file rather than just to the console?
Second, is it even possible for python to look through a text file and extract certain lines based on the values in that line?
Some sample output from the first API call:
"name":
"type":
"hosts_list":
"username":
I've come across some things describing how to convert lines of a text file into individual objects, but that only allows me to print lines based on the number line they are in a text file, it doesn't print lines based on the content in their lines.
Also, if this is possible, the "hosts_list" line may cause an issue because it actually has a subsection that can contain multiple entries. In the above example the subsection is:
I'm working on a multi-step process where I run one python script that makes an API call to a system. I then have to extract some of those values from that output so that I can submit them, along with a new password, via a second API call that I would make after.
I have two main questions, first, is it possible to pipe the output of the initial API call directly to a text file rather than just to the console?
Second, is it even possible for python to look through a text file and extract certain lines based on the values in that line?
Some sample output from the first API call:
Output:{
"LINE_1": true,
"LINE_2": "Post \"https://a:443/sdk\": dial tcp: lookup a on 1.1.127.252:53: no such host",
"EXAMPLE_3": "",
"created_at": 1648040001,
"deleted": false,
"deleted_at": 0,
"delta_interval": 60,
"description": "API's Testing.",
"disable_backup": false,
"hosts_list": [
{
"host_name": "TestingHost",
"port_number": 443
}
],
"id": "623b1841755f021ebe269xyz",
"name": "Tester",
"password": "",
"scope_id": "5f7e2a15497d4f48a9605687",
"type": "vcenter",
}
There are four specific lines I am trying to extract: "name":
"type":
"hosts_list":
"username":
I've come across some things describing how to convert lines of a text file into individual objects, but that only allows me to print lines based on the number line they are in a text file, it doesn't print lines based on the content in their lines.
Also, if this is possible, the "hosts_list" line may cause an issue because it actually has a subsection that can contain multiple entries. In the above example the subsection is:
Output: {
"host_name": "TestingHost",
"port_number": 443
}
Thank you for any help you can provide.