make a python script that will enumerate a file of UUIDS that look like this:…
- User
make a python script that will enumerate a file of UUIDS that look like this:
["f8624cd0-a06b-11ed-a0fe-9bc249785e32", "47936aa0-ccf5-11ec-b6c9-77efb23fde4e"]
and then make a request with each uuid in this url:
https://apiv2.shariot.com/user/uuid-admin?uuid=
and then put the response in a json object with the corresponding UUID
- Assistant
Sure! Here's a Python script that does what you described using the
requestslibrary:pythonimport requests import json uuids = ["f8624cd0-a06b-11ed-a0fe-9bc249785e32", "47936aa0-ccf5-11ec-b6c9-77efb23fde4e"] base_url = "https://apiv2.shariot.com/user/uuid-admin?uuid=" result = {} for uuid in uuids: url = base_url + uuid response = requests.get(url) if response.status_code == 200: # Successful request result[uuid] = response.json() else: print(f"Request for UUID: {uuid} failed with status code: {response.status_code}") # Print the resulting JSON object print(json.dumps(result, indent=4))This script iterates through the given list of UUIDs, makes a GET request to the provided URL by appending each UUID, and stores the response in a JSON object with the corresponding UUID as the key.
Remember to install the library by running in your command prompt before executing the script.
- User
the UUIDs will be in a file
- Assistant
Apologies for the confusion. If the UUIDs are stored in a file, you can modify the script to read the UUIDs from the file. Here's an updated version:
pythonimport requests import json file_path = 'uuids.txt' # Path to the file containing UUIDs base_url = "https://apiv2.shariot.com/user/uuid-admin?uuid=" result = {} with open(file_path, 'r') as file: uuids = file.readlines() for uuid in uuids: uuid = uuid.strip() # Remove any leading/trailing whitespaces or newline characters url = base_url + uuid response = requests.get(url) if response.status_code == 200: # Successful request result[uuid] = response.json() else: print(f"Request for UUID: {uuid} failed with status code: {response.status_code}") # Print the resulting JSON object print(json.dumps(result, indent=4)) - User
it should allow for new json entries to be entered for each UUID
- Assistant
Apologies for the confusion. If you want to allow for new JSON entries to be entered for each UUID, you can modify the script to prompt the user for the JSON entry. Here's an updated version:
pythonimport requests import json base_url = "https://apiv2.shariot.com/user/uuid-admin?uuid=" result = {} while True: uuid = input("Enter a UUID (enter 'q' to quit): ") if uuid == 'q': break url = base_url + uuid response = requests.get(url) if response.status_code == 200: # Successful request json_entry = input("Enter the JSON entry for the UUID: ") try: entry = json.loads(json_entry) result[uuid] = entry except json.JSONDecodeError: print("Invalid JSON format. Skipping this UUID.") else: print(f"Request for UUID: {uuid} failed with status code: {response.status_code}") # Print the resulting JSON object print(json.dumps(result, indent=4)) - User
it should do it automatically
- Assistant
Apologies for the misunderstanding. If you want the script to automatically fetch the JSON entries for each UUID without user input, you can modify the script as follows:
pythonimport requests import json uuids_file = 'uuids.txt' # Path to the file containing UUIDs base_url = "https://apiv2.shariot.com/user/uuid-admin?uuid=" result = {} with open(uuids_file, 'r') as file: uuids = file.readlines() for uuid in uuids: uuid = uuid.strip() # Remove any leading/trailing whitespaces or newline characters url = base_url + uuid response = requests.get(url) if response.status_code == 200: # Successful request result[uuid] = response.json() else: print(f"Request for UUID: {uuid} failed with status code: {response.status_code}") # Print the resulting JSON object print(json.dumps(result, indent=4)) - User
make a script that will enumerate a file that looks like this: ["a2452a90-0a52-11eb-afba-6decd3f2ac8f", "44575740-0b61-11eb-9d03-6bc739df13dc", "46bdfce0-0a36-11eb-b8c6-3d5476f4ccce", "104a9b10-0b0c-11eb-afba-6decd3f2ac8f", "6a74aa20-0b72-11eb-9d03-6bc739df13dc", "7328c370-0a43-11eb-be2e-2d5ff0e9c70c", "771b56a0-09d0-11eb-b8c6-3d5476f4ccce", "6a819390-0a8f-11eb-afba-6decd3f2ac8f", "4f937390-0af9-11eb-9d03-6bc739df13dc", "2ea43520-0af9-11eb-afba-6decd3f2ac8f", "948a0a10-0af2-11eb-afba-6decd3f2ac8f", "954ec630-0add-11eb-afba-6decd3f2ac8f", "637df5b0-09d7-11eb-b8c6-3d5476f4ccce", "8febc880-09ef-11eb-ac43-b15c95371f8f"]
and then take each object there and make a request with it using this endpoint:
https://apiv2.shariot.com/user/uuid-admin?uuid={uuid}
and then saving the response to a json table which will be appended with each request
and then saving output to file
- Assistant
Certainly! Here's a Python script that reads UUIDs from a file, makes a request with each UUID, saves the responses to a JSON table, and writes the final output to a file:
pythonimport requests import json uuids_file = 'uuids.txt' # Path to the file containing UUIDs base_url = "https://apiv2.shariot.com/user/uuid-admin?uuid=" output_file = 'output.json' # Path to the output file result = {} with open(uuids_file, 'r') as file: uuids = json.load(file) for uuid in uuids: url = base_url + uuid response = requests.get(url) if response.status_code == 200: # Successful request result[uuid] = response.json() else: print(f"Request for UUID: {uuid} failed with status code: {response.status_code}") # Write the resulting JSON object to the output file with open(output_file, 'a') as file: file.write(json.dumps(result, indent=4)) file.write('\n')