-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupload.py
34 lines (25 loc) · 838 Bytes
/
upload.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
import sys
import requests
from os import getenv
MOD_PORTAL_URL = "https://mods.factorio.com"
INIT_UPLOAD_URL = f"{MOD_PORTAL_URL}/api/v2/mods/releases/init_upload"
apikey = getenv("MOD_UPLOAD_API_KEY")
modname = getenv("MOD_UPLOAD_NAME")
zipfilepath = getenv("MOD_UPLOAD_FILE")
request_body = data={"mod":modname}
request_headers = {"Authorization": f"Bearer {apikey}"}
response = requests.post(
INIT_UPLOAD_URL,
data=request_body,
headers=request_headers)
if not response.ok:
print(f"init_upload failed: {response.text}")
sys.exit(1)
upload_url = response.json()["upload_url"]
with open(zipfilepath, "rb") as f:
request_body = {"file": f}
response = requests.post(upload_url, files=request_body)
if not response.ok:
print(f"upload failed: {response.text}")
sys.exit(1)
print(f"upload successful: {response.text}")