-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.py
45 lines (37 loc) · 1.58 KB
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import requests
from payload_storage import save_payload
def fetch_url(url):
response = requests.get(url)
if response.status_code == 200:
return {"status": "fetched", "url": url, "content": response.text}
else:
return {"status": "error", "url": url, "content": None}
def main():
while True:
# Print the command prompt in green
print("\033[92mrouteai\033[0m")
# Prompt the user to enter a URL
url = input("Please enter a URL: ")
# Fetch the URL
fetch_result = fetch_url(url)
print(f"Documentation been read from {url}")
# Prompt the user for the next action
action = input("Where do you want to post your call or save the data received? ")
if action == "query":
# Handle the query command
api_key = input("Please enter your API key: ")
endpoint = input("Please enter the endpoint: ")
payload = input("Please enter the payload (in JSON format): ")
# Send a request to the fetched API
response = requests.post(endpoint, headers={"Authorization": f"Bearer {api_key}"}, json=payload)
print(f"Response: {response.json()}")
elif action == "save":
# Save the data received
key = input("Please enter the key to save the data: ")
save_payload(key, fetch_result["content"])
print(f"Data saved with key: {key}")
else:
print("Invalid action. Please try again.")
if __name__ == "__main__":
main()