To download an archive of the project as is. This uses Python3 with a bunch of libraries like requests that you may need to install. This is very specific to my folder structure so you will need to change a few lines/folder paths.
import sys
import requests
import time
import subprocess
import os
import shutil
import zipfile
import io
import re
FNULL = open(os.devnull, 'w')
snapshot_path = '../snapshots-project'
project_id = '475452'
export_url = 'https://playcanvas.com/api/projects/{}/export'.format(project_id)
job_url_template = 'https://playcanvas.com/api/jobs/{}'
headers = {
'Authorization':'Bearer fkldjsflfjfjklejflsefjeklsf',
'Content-Type':'application/json'
}
job_poll_interval_secs = 1
job_id = -1
archive_url = ''
# Request the archive of the project
print('Requesting project archive job')
r = requests.post(export_url, headers=headers)
if r.status_code == 200:
json = r.json()
status = json['status']
if status == 'running':
job_id = json['id']
elif status == 'complete':
archive_url = json['url']
else:
sys.exit(1)
else:
print('Error: {}'.format(r.status_code))
sys.exit(1)
if len(archive_url) == 0:
print('Waiting for job to complete')
# Poll job till its complete
job_url = job_url_template.format(str(job_id))
job_finished = False
while not job_finished:
r = requests.get(job_url, headers=headers)
if r.status_code == 200:
json = r.json()
status = json['status']
if status == 'complete':
archive_url = json['data']['url']
job_finished = True
elif status == 'running':
print('Still waiting')
time.sleep(job_poll_interval_secs)
else:
sys.exit(1)
else:
sys.exit(1)
# Remove all files from the snapshot directory
print('Clearing snapshot directory')
shutil.rmtree(snapshot_path)
os.mkdir(snapshot_path)
# Download zip from JSON response
print('Download archive from {}'.format(archive_url))
r = requests.get(archive_url)
z = zipfile.ZipFile(io.BytesIO(r.content))
# Unzip the archive
print('Unzipping archive')
z.extractall(snapshot_path)
To download a hostable version (basically ‘build’ the project) Same thing, it is very specific to my folder structure:
import sys
import requests
import time
import subprocess
import os
import shutil
import zipfile
import io
import re
FNULL = open(os.devnull, 'w')
build_path = '../build'
export_url = 'https://playcanvas.com/api/apps/download'
job_url_template = 'https://playcanvas.com/api/jobs/{}'
headers = {
'Authorization':'Bearer kldsjfklfjkdfjdklsfjdslfdk',
'Content-Type':'application/json'
}
data = '{"project_id":475452, "name":"Iso Base Builder", "scripts_concatenate":true }'
job_poll_interval_secs = 1
job_id = -1
download_url = ''
# Request the download of the project
print('Requesting project download job')
r = requests.post(export_url, headers=headers, data=data)
if r.status_code == 201:
json = r.json()
status = json['status']
if status == 'running':
job_id = json['id']
elif status == 'complete':
download_url = json['url']
else:
sys.exit(1)
else:
print('Error: {}'.format(r.status_code))
sys.exit(1)
if len(download_url) == 0:
print('Waiting for job to complete')
# Poll job till its complete
job_url = job_url_template.format(str(job_id))
job_finished = False
while not job_finished:
r = requests.get(job_url, headers=headers)
if r.status_code == 200:
json = r.json()
status = json['status']
if status == 'complete':
download_url = json['data']['download_url']
job_finished = True
elif status == 'running':
print('Still waiting')
time.sleep(job_poll_interval_secs)
else:
sys.exit(1)
else:
sys.exit(1)
# Remove all files from the snapshot directory
print('Clearing snapshot directory')
shutil.rmtree(build_path)
os.mkdir(build_path)
# Download zip from JSON response
print('Download archive from {}'.format(download_url))
r = requests.get(download_url)
z = zipfile.ZipFile(io.BytesIO(r.content))
# Unzip the archive
print('Unzipping archive')
z.extractall(build_path)