29 lines
728 B
Plaintext
29 lines
728 B
Plaintext
|
#!/usr/bin/env python3
|
||
|
import json
|
||
|
import os
|
||
|
import urllib.request
|
||
|
from pathlib import Path
|
||
|
from typing import Dict
|
||
|
|
||
|
|
||
|
def upload_files(file_dict: Dict[str, str]) -> str:
|
||
|
data = json.dumps(file_dict).encode()
|
||
|
|
||
|
url = "https://api.markprompt.com/train"
|
||
|
headers = {
|
||
|
"Authorization": f'Bearer {os.getenv("MARKPROMPT_API_KEY", "")}',
|
||
|
"Content-Type": "application/json",
|
||
|
}
|
||
|
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
|
||
|
response = urllib.request.urlopen(req)
|
||
|
result = response.read()
|
||
|
return result.decode("utf-8")
|
||
|
|
||
|
|
||
|
files = {}
|
||
|
for file in Path(".").glob("**/*.md"):
|
||
|
with file.open() as f:
|
||
|
files[str(file)] = f.read()
|
||
|
|
||
|
print(upload_files(files))
|