30 lines
810 B
Python
30 lines
810 B
Python
|
|
import paramiko, time, json
|
||
|
|
|
||
|
|
NAS_HOST = "100.85.152.112"
|
||
|
|
NAS_PORT = 22
|
||
|
|
NAS_USER = "simon"
|
||
|
|
NAS_PASS = "Nas82829330"
|
||
|
|
|
||
|
|
def exec_and_read(c, cmd, wait=3):
|
||
|
|
stdin, stdout, stderr = c.exec_command(cmd)
|
||
|
|
time.sleep(wait)
|
||
|
|
while not stdout.channel.exit_status_ready():
|
||
|
|
time.sleep(0.2)
|
||
|
|
return stdout.read().decode("utf-8", errors="replace")
|
||
|
|
|
||
|
|
def main():
|
||
|
|
c = paramiko.SSHClient()
|
||
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
|
|
c.connect(NAS_HOST, NAS_PORT, NAS_USER, NAS_PASS, timeout=15)
|
||
|
|
|
||
|
|
out = exec_and_read(c, "curl -s http://localhost:8080/api/questionnaires", wait=3)
|
||
|
|
data = json.loads(out)
|
||
|
|
|
||
|
|
print(f"\n问卷数量: {len(data)}")
|
||
|
|
for i, q in enumerate(data, 1):
|
||
|
|
print(f" {i}. {q['title']}")
|
||
|
|
|
||
|
|
c.close()
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|