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.
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from call_api import *
|
|
from read_api_details import parse_csv_to_dict
|
|
import json
|
|
|
|
def main():
|
|
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()
|
|
if not api_call.find(".php") > 0:
|
|
api_call += ".php"
|
|
print(details[api_call])
|
|
# Prompt the user for the method
|
|
method = input("Enter the HTTP method (POST/GET): ").strip().upper()
|
|
|
|
# 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
|
|
|
|
# Call the API
|
|
try:
|
|
response = call_api_preloaded(api_call, 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() |