-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsubmit.py
More file actions
39 lines (31 loc) · 1.08 KB
/
submit.py
File metadata and controls
39 lines (31 loc) · 1.08 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
#!/usr/bin/env python3
import os
import requests
import json
import re
def sanitize_filename(name):
sanitized = re.sub(r'[^a-zA-Z0-9._-]', '_', name)
if sanitized and not sanitized[0].isalnum():
sanitized = 'team_' + sanitized
return sanitized
def main():
with open('team.json', 'r') as f:
team_data = json.load(f)
team_name = sanitize_filename(team_data['name'])
routing_file = "ar_hackathon/api/routing.py"
renamed_file = f"{team_name}_routing.py"
if not os.path.exists(routing_file):
print(f"Error: {routing_file} not found")
return
s3_url = f"https://arhackathon.s3.us-east-1.amazonaws.com/{renamed_file}"
try:
with open(routing_file, 'rb') as f:
response = requests.put(s3_url, data=f)
if response.status_code == 200:
print(f"Successfully uploaded {renamed_file}")
else:
print(f"Upload failed: {response.status_code} - {response.text}")
except Exception as e:
print(f"Upload failed: {e}")
if __name__ == "__main__":
main()