-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.py
34 lines (25 loc) · 856 Bytes
/
publish.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 os
import sys
import requests
MOD_PORTAL_URL = "https://mods.factorio.com"
INIT_UPLOAD_URL = f"{MOD_PORTAL_URL}/api/v2/mods/releases/init_upload"
apikey = os.environ["FACTORION_MOD_API_KEY"]
modname = os.environ["MOD_NAME"]
filepath = os.environ["RELEASE_ARTIFACT_PATH"]
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(filepath, "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}")