You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.8 KiB
Python

from call_api import call_api
from read_api_details import parse_csv_to_dict
import json
def main():
base_url = "https://192.168.49.1/tool/" # Replace with your actual base URL
details = parse_csv_to_dict("apidetails.csv")
print(details.keys())
# Prompt the user for the API call
api_call = input("Enter the API call (e.g., about.php): ").strip()
full_url = base_url + api_call
print(details[api_call])
# Prompt the user for the method
method = input("Enter the HTTP method (POST/GET): ").strip().upper()
auto_include = []
if 'PARAM' in details[api_call]:
for param, val in details[api_call]["PARAM"].items():
# print(param, val)
if val == method:
print(param, end="")
if 'KEY' in details[api_call]:
for keyname, key in details[api_call]["KEY"].items():
if keyname == param:
print("=" + key, end="")
auto_include.append((keyname, key))
print("")
# Prompt the user for parameters
params = {}
while True:
param_name = input("Enter parameter name (or press enter to finish): ").strip()
if param_name == "":
break
param_value = input(f"Enter value for '{param_name}': ").strip()
params[param_name] = param_value
for param in auto_include:
params[param[0]] = param[1]
# Call the API
try:
response = call_api(full_url, method, params)
print("Response Status Code:", response.status_code)
try:
print("Response JSON:", json.dumps(response.json(), indent=2))
except ValueError:
print("Response Text:", response.text)
except Exception as e:
print("Error:", str(e))
if __name__ == "__main__":
main()