Skip to content

Instantly share code, notes, and snippets.

@Sdy603
Last active November 15, 2024 14:14
Show Gist options
  • Save Sdy603/e5f8cb6622d43e733793aef1c557d99d to your computer and use it in GitHub Desktop.
Save Sdy603/e5f8cb6622d43e733793aef1c557d99d to your computer and use it in GitHub Desktop.
import csv
import requests
import time
from datetime import datetime
# Define constants
API_URL = "https://ACCOUNT.getdx.net/api/deployments.create"
BEARER_TOKEN = "token"
# Function to convert datetime to Unix timestamp
def datetime_to_unix(timestamp):
dt = datetime.strptime(timestamp, "%d/%m/%Y %H:%M")
return int(dt.timestamp())
# Read CSV and prepare the payload
with open("Deployments.csv", mode="r") as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
payload = {
"reference_id": row["reference_id"],
"deployed_at": datetime_to_unix(row["deployed_at"]),
"service": row["service"],
"commit_sha": row["commit_sha"],
"repository": row["repository"],
"source_url": row["source_url"],
"metadata": {
"version": row["version"],
"pr_merge_time": row["pr_merge_time"],
"uat_deploy_start_time": row["uat_deploy_start_time"],
"created_by": row["created_by"]
}
}
# Send the request
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {BEARER_TOKEN}"
}
response = requests.post(API_URL, json=payload, headers=headers)
# Check the response
if response.status_code == 200:
print(f"Deployment for {row['service']} was successful.")
else:
print(f"Failed to send deployment data for {row['service']}. Status Code: {response.status_code}")
print("Response:", response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment