Skip to content

Instantly share code, notes, and snippets.

@Fcukit
Created August 29, 2018 11:26
Show Gist options
  • Save Fcukit/2936a8e640db9af1dfbae5e424918517 to your computer and use it in GitHub Desktop.
Save Fcukit/2936a8e640db9af1dfbae5e424918517 to your computer and use it in GitHub Desktop.
import requests
res = requests.post('http://localhost:8000/api/token-auth/',
data={'username': 'admin',
'password': 'admin'}).json()
token = res['token']
res = requests.post('http://localhost:8000/api/projects/',
headers={'Authorization': 'JWT {}'.format(token)},
data={'name': 'Hello WebODM!'}).json()
project_id = res['id']
images = [
('images', ('image1.jpg', open('image1.jpg', 'rb'), 'image/jpg')),
('images', ('image2.jpg', open('image2.jpg', 'rb'), 'image/jpg')),
# ...
]
options = json.dumps([
{'name': "orthophoto-resolution", 'value': 24}
])
res = requests.post('http://localhost:8000/api/projects/{}/tasks/'.format(project_id),
headers={'Authorization': 'JWT {}'.format(token)},
files=images,
data={
'options': options
}).json()
task_id = res['id']
while True:
res = requests.get('http://localhost:8000/api/projects/{}/tasks/{}/'.format(project_id, task_id),
headers={'Authorization': 'JWT {}'.format(token)}).json()
if res['status'] == status_codes.COMPLETED:
print("Task has completed!")
break
elif res['status'] == status_codes.FAILED:
print("Task failed: {}".format(res))
sys.exit(1)
else:
print("Processing, hold on...")
time.sleep(3)
res = requests.get("http://localhost:8000/api/projects/{}/tasks/{}/download/orthophoto.tif".format(project_id, task_id),
headers={'Authorization': 'JWT {}'.format(token)},
stream=True)
with open("orthophoto.tif", 'wb') as f:
for chunk in res.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
print("Saved ./orthophoto.tif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment