-
-
Save Fcukit/2936a8e640db9af1dfbae5e424918517 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| res = requests.post('http://localhost:8000/api/token-auth/', | |
| data={'username': 'admin', | |
| 'password': 'admin'}).json() | |
| token = res['token'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| res = requests.post('http://localhost:8000/api/projects/', | |
| headers={'Authorization': 'JWT {}'.format(token)}, | |
| data={'name': 'Hello WebODM!'}).json() | |
| project_id = res['id'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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