Akwbw commited on
Commit
49fdb76
Β·
verified Β·
1 Parent(s): ebb1574

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +39 -0
main.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from browser_controller import BrowserController
3
+
4
+ app = Flask(__name__)
5
+ browser = BrowserController()
6
+
7
+ @app.route("/command", methods=["POST"])
8
+ def command():
9
+ data = request.json
10
+ action = data.get("action")
11
+ selector = data.get("selector")
12
+ value = data.get("value")
13
+ pixels = data.get("pixels", 0)
14
+ url = data.get("url")
15
+
16
+ try:
17
+ if action == "navigate" and url:
18
+ result = browser.navigate(url)
19
+ elif action == "click" and selector:
20
+ result = browser.click(selector)
21
+ elif action == "type" and selector and value:
22
+ result = browser.type_text(selector, value)
23
+ elif action == "scroll":
24
+ result = browser.scroll(pixels)
25
+ else:
26
+ return jsonify({"error": "Invalid command"}), 400
27
+
28
+ return jsonify(result)
29
+
30
+ except Exception as e:
31
+ return jsonify({"error": str(e)}), 500
32
+
33
+ @app.route("/close", methods=["POST"])
34
+ def close_browser():
35
+ browser.close()
36
+ return jsonify({"status": "browser closed"})
37
+
38
+ if __name__ == "__main__":
39
+ app.run(host="0.0.0.0", port=5000)