cleanup
This commit is contained in:
@ -9,14 +9,11 @@ import json
|
||||
import argparse
|
||||
import random
|
||||
|
||||
token = "ich-bin-da-token"
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"Content-Type": "application/json", # Adjust if needed for your payload format
|
||||
}
|
||||
|
||||
def send_post_request(uri, data):
|
||||
def send_post_request(uri, data, token):
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
try:
|
||||
requests.post(uri, json=data, timeout=1, headers=headers)
|
||||
except requests.exceptions.RequestException as e:
|
||||
@ -31,6 +28,11 @@ def main():
|
||||
type=str,
|
||||
help="The URI to send POST requests to (e.g., http://127.0.0.1:8080/api)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"token",
|
||||
type=str,
|
||||
help="Bearer authorization token)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"directory",
|
||||
type=str,
|
||||
@ -53,7 +55,7 @@ def main():
|
||||
try:
|
||||
data = json.load(file)
|
||||
print(f"Sending {args.directory} to {args.uri}")
|
||||
send_post_request(args.uri, data)
|
||||
send_post_request(args.uri, data, args.token)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error reading {args.directory}: {e}")
|
||||
return
|
||||
@ -74,7 +76,7 @@ def main():
|
||||
try:
|
||||
data = json.load(file)
|
||||
print(f"Sending {filename} to {args.uri}")
|
||||
send_post_request(args.uri, data)
|
||||
send_post_request(args.uri, data, args.token)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error reading {filename}: {e}")
|
||||
|
||||
@ -85,7 +87,7 @@ def main():
|
||||
try:
|
||||
data = json.load(file)
|
||||
print(f"Sending {filename} to {args.uri}")
|
||||
send_post_request(args.uri, data)
|
||||
send_post_request(args.uri, data, args.token)
|
||||
input("Press Enter to send the next file...")
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error reading {filename}: {e}")
|
||||
@ -98,11 +100,10 @@ def main():
|
||||
try:
|
||||
data = json.load(file)
|
||||
print(f"Sending {filename} to {args.uri}")
|
||||
send_post_request(args.uri, data)
|
||||
send_post_request(args.uri, data, args.token)
|
||||
input("Press Enter to send another random file...")
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error reading {filename}: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user