Initial commit
Added uploader
This commit is contained in:
commit
9dd9c6cd5f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
venv/
|
30
upload.py
Normal file
30
upload.py
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import yaml
|
||||
import requests
|
||||
from urllib.parse import urljoin
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage:")
|
||||
print("upload.py [URL_BASE] [SOURCE_FILE]")
|
||||
return
|
||||
|
||||
urlbase = sys.argv[1]
|
||||
source_file = sys.argv[2]
|
||||
|
||||
with open(source_file, "r") as f:
|
||||
program = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
||||
print("Uploading...")
|
||||
target_url = urljoin(urlbase, "program")
|
||||
r = requests.post(target_url, json=program)
|
||||
r.raise_for_status()
|
||||
print(f"Upload complete, id of the uploaded program: {r.json['_id']}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user