-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstream.py
More file actions
25 lines (22 loc) · 792 Bytes
/
stream.py
File metadata and controls
25 lines (22 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import sys, os, json
import requests as req
from urllib.parse import urlparse, urlunparse
def main(argv):
#print(argv)
#argv=['stream/demo']
url = urlparse(os.getenv("OPSDEV_APIHOST"))
netloc = f"stream.{url.netloc}"
path = f"/web/{os.getenv("OPSDEV_USERNAME")}/{argv[0]}"
streamer = urlunparse(url._replace(netloc=netloc, path=path))
msg = {"input": " ".join(argv[1:])} if len(argv)>1 else {}
lines = req.post(streamer, json=msg, stream=True).iter_lines()
for line in lines:
#line = next(lines)
msg = json.loads(line.decode("utf-8")).get("output", "")
if msg != "":
print(msg, end="", flush=True)
else:
print()
break
if __name__ == "__main__":
main(sys.argv[1:])