-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_application.py
More file actions
65 lines (51 loc) · 1.75 KB
/
my_application.py
File metadata and controls
65 lines (51 loc) · 1.75 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import json
import hmac
import hashlib
import requests
from datetime import datetime, timezone
def create_signature(payload_json, secret):
"""Create HMAC-SHA256 signature for the payload."""
signature = hmac.new(
secret.encode("utf-8"), payload_json.encode("utf-8"), hashlib.sha256
).hexdigest()
return f"sha256={signature}"
def main():
name = os.environ.get("APPLICANT_NAME")
email = os.environ.get("APPLICANT_EMAIL")
resume_link = os.environ.get("RESUME_LINK")
repository_link = os.environ.get("REPOSITORY_LINK")
action_run_link = os.environ.get("ACTION_RUN_LINK")
# Create payload
payload = {
"action_run_link": action_run_link,
"email": email,
"name": name,
"repository_link": repository_link,
"resume_link": resume_link,
"timestamp": datetime.now(timezone.utc)
.isoformat(timespec="milliseconds")
.replace("+00:00", "Z"),
}
# Serialize
payload_json = json.dumps(
payload, separators=(",", ":"), sort_keys=True, ensure_ascii=False
)
# Create signature
signing_secret = "hello-there-from-b12"
signature = create_signature(payload_json, signing_secret)
# Make POST request
headers = {"Content-Type": "application/json", "X-Signature-256": signature}
response = requests.post(
"https://b12.io/apply/submission",
data=payload_json.encode("utf-8"),
headers=headers,
)
# Check response
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
if response.status_code != 200:
raise Exception(f"Submission failed with status code {response.status_code}")
print("Submission successful!")
if __name__ == "__main__":
main()