Initial commit

Added uploader
This commit is contained in:
Pünkösd Marcell 2021-04-25 04:44:25 +02:00
commit 9dd9c6cd5f
2 changed files with 31 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv/

30
upload.py Normal file
View 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()