-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (48 loc) · 1.59 KB
/
main.py
File metadata and controls
65 lines (48 loc) · 1.59 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import ctypes
import os
from flask import Flask, request
import logging
import json
app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)
@app.route("/test", methods=["GET"])
def test():
logging.info("Test")
response = {
"version": "1.0.0",
"session": "bebra",
"response": {
"end_session": False
}
}
return json.dumps(response)
def lock_windows():
ctypes.windll.user32.LockWorkStation()
def disable_pc():
os.system("shutdown /s /t 1")
@app.route("/", methods=["POST"])
def main():
logging.info(request.json)
response = {
"version": request.json["version"],
"session": request.json["session"],
"response": {
"end_session": False
}
}
req = request.json
input_words = req["request"]["nlu"]["tokens"]
if req["session"]["new"]:
response["response"]["text"] = "Теперь вы можете управлять компьютером!"
else:
if any(ext in input_words for ext in ["заблокируй", "экран"]):
lock_windows()
response["response"]["text"] = "Экран заблокирован"
response["response"]["end_session"] = True
elif any(ext in input_words for ext in ["выключи", "выруби"]):
disable_pc()
response["response"]["text"] = "Выключаю компьютер"
response["response"]["end_session"] = True
else:
response["response"]["text"] = "Неизвестная команда"
return json.dumps(response)