Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, send_file
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
@app.route("/")
|
| 8 |
+
def home():
|
| 9 |
+
return '''
|
| 10 |
+
<h2>Web to APK Builder</h2>
|
| 11 |
+
<form method="POST" action="/build">
|
| 12 |
+
<input name="url" placeholder="https://your-site.com" style="width:300px;">
|
| 13 |
+
<button type="submit">Build APK</button>
|
| 14 |
+
</form>
|
| 15 |
+
'''
|
| 16 |
+
|
| 17 |
+
@app.route("/build", methods=["POST"])
|
| 18 |
+
def build():
|
| 19 |
+
url = request.form.get("url")
|
| 20 |
+
|
| 21 |
+
project_name = "myapp"
|
| 22 |
+
|
| 23 |
+
# حذف مشروع قديم
|
| 24 |
+
if os.path.exists(project_name):
|
| 25 |
+
subprocess.run(["rm", "-rf", project_name])
|
| 26 |
+
|
| 27 |
+
# إنشاء مشروع Capacitor
|
| 28 |
+
subprocess.run(["npx", "create-react-app", project_name])
|
| 29 |
+
os.chdir(project_name)
|
| 30 |
+
|
| 31 |
+
# تثبيت Capacitor
|
| 32 |
+
subprocess.run(["npm", "install", "@capacitor/core", "@capacitor/cli"])
|
| 33 |
+
subprocess.run(["npx", "cap", "init", "MyApp", "com.example.myapp"])
|
| 34 |
+
|
| 35 |
+
# تعديل WebView لفتح URL
|
| 36 |
+
with open("src/App.js", "w") as f:
|
| 37 |
+
f.write(f"""
|
| 38 |
+
import React from "react";
|
| 39 |
+
function App() {{
|
| 40 |
+
window.location.href = "{url}";
|
| 41 |
+
return <h1>Loading...</h1>;
|
| 42 |
+
}}
|
| 43 |
+
export default App;
|
| 44 |
+
""")
|
| 45 |
+
|
| 46 |
+
subprocess.run(["npm", "run", "build"])
|
| 47 |
+
|
| 48 |
+
subprocess.run(["npx", "cap", "add", "android"])
|
| 49 |
+
subprocess.run(["npx", "cap", "copy"])
|
| 50 |
+
|
| 51 |
+
# بناء APK
|
| 52 |
+
os.chdir("android")
|
| 53 |
+
subprocess.run(["./gradlew", "assembleDebug"])
|
| 54 |
+
|
| 55 |
+
apk_path = "app/build/outputs/apk/debug/app-debug.apk"
|
| 56 |
+
|
| 57 |
+
return send_file(apk_path, as_attachment=True)
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
app.run()
|