from django.urls import path as site
from django.shortcuts import HttpResponse
from os import system, remove, environ
from base64 import a85decode, b64encode
from sys import path
from requests import get
from pyautogui import screenshot
from tkinter import Tk
from time import strftime, sleep
from cv2 import VideoCapture, imwrite
from pyttsx3 import init as ttsInit
# 定义 TTS 朗读者
tts_name = []
engine = ttsInit()
voices = engine.getProperty('voices')
for voice in voices:
tts_name.append(voice.name)
engine.stop()
del engine
tts_name.append('Windows SAPI.spVoice')
# 求最大公因数
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
# 适配图片比例
def change(a, b):
x = gcd(a, b)
a /= x
b /= x
while a < 500 or b < 500:
a *= 2
b *= 2
return (a, b)
# 拍照
def get_photo():
cap = VideoCapture(0)
f, frame = cap.read()
imwrite("./photo.png", frame)
with open("./photo.png", "rb") as f:
temp = b64encode(f.read()).decode()
remove("./photo.png")
cap.release()
return "data:image/png;base64,%s" % temp
# 主页
def main(request):
return HttpResponse(
"""
"""
)
# 运行
def run(request):
system("chcp 65001 >nul")
text = request.POST.get("command")
code = request.POST.get("code")
runf = request.FILES.get("runf")
echo = request.POST.get("echo")
if code: # 优先级最高的 执行批处理脚本
with open("temp.bat", "w", encoding="utf-8") as f:
f.write(code + "\nexit")
system("start %s\\temp.bat" % path[0])
if runf: # 次之的应用程序
with open("temp.exe", "wb") as f:
f.write(b"")
with open("temp.exe", "wb") as f:
for i in runf.chunks():
f.write(i)
system("start %s\\temp.exe" % path[0])
if text: # 最后是直接执行命令
system(text)
if echo: # 带回显的执行命令
try:
remove("temp.txt")
except:
pass
system("%s >> temp.txt" % echo)
with open("temp.txt", "r", encoding="utf-8") as f:
ret = f.read().splitlines()
s = ""
for i in ret:
s += "