File size: 2,306 Bytes
991ecaf 110bc66 991ecaf 0511a46 110bc66 8255c62 841b576 8255c62 664f192 110bc66 664f192 f21d46e 8255c62 664f192 0511a46 110bc66 664f192 8255c62 664f192 110bc66 841b576 110bc66 0511a46 110bc66 0511a46 110bc66 0511a46 110bc66 0511a46 664f192 0511a46 664f192 f21d46e 8255c62 f21d46e f5daecf 0511a46 664f192 0511a46 f5daecf 0511a46 110bc66 0511a46 110bc66 0511a46 f5daecf 0511a46 f5daecf |
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import os
import subprocess
import time
# Display set karna
os.environ["DISPLAY"] = ":99"
import base64
from flask import Flask, request, jsonify
from flask_cors import CORS
import pyautogui
# mss hata diya hai, hum direct system command use karenge (failsafe)
app = Flask(__name__)
CORS(app)
SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768
pyautogui.FAILSAFE = False
@app.route('/')
def home():
return "Botisbot Cloud PC (Fluxbox Edition) Ready!"
@app.route('/snapshot', methods=['GET'])
def get_snapshot():
try:
# METHOD: Direct System Command (Sabse reliable method)
# Hum 'scrot' use karke image temp file mein save karenge aur fir read karenge
filename = "/tmp/screen.jpg"
# Scrot command: -z (silent), -o (overwrite), -q 50 (quality 50%)
subprocess.run(["scrot", "-z", "-o", "-q", "50", filename], check=True)
# Image read karo
with open(filename, "rb") as image_file:
b64 = base64.b64encode(image_file.read()).decode('utf-8')
return jsonify({"screenshot": b64})
except Exception as e:
print(f"Snapshot Error: {e}")
# Agar error aaye to user ko batao
return jsonify({"error": str(e)}), 500
@app.route('/interact', methods=['POST'])
def interact():
data = request.json
action = data.get('action')
try:
if action == 'tap':
x = int(data.get('x') * SCREEN_WIDTH)
y = int(data.get('y') * SCREEN_HEIGHT)
pyautogui.click(x, y)
elif action == 'type':
pyautogui.write(data.get('text'))
elif action == 'key':
k = data.get('key').lower()
if k == 'enter': pyautogui.press('enter')
elif k == 'backspace': pyautogui.press('backspace')
elif action == 'scroll':
pyautogui.scroll(-5)
elif action == 'open_terminal':
subprocess.Popen(["xterm", "&"])
elif action == 'open_browser':
subprocess.Popen(["chromium-browser", "--no-sandbox"])
return jsonify({"status": "ok"})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, threaded=True) |