Team Ai
Apppublic

jasy0/databaseTester

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py58 linesDownload Raw Back to root
1from flask import Flask, request2import re3import subprocess4 5app = Flask(__name__)6 7def extract_manga_id(url):8    """9    Extracts the MangaDex manga ID from the provided URL using regex.10    """11    match = re.search(r"https://mangadex.org/title/([^/]+)/", url)12    return match.group(1) if match else None13 14@app.route("/", methods=["GET", "POST"])15def index():16    """17    Handles the main web page for submitting a MangaDex URL.18    """19    if request.method == "POST":20        # Retrieve the URL from the form submission21        mangadex_url = request.form.get("url")22        23        # Extract the Manga ID from the provided URL24        manga_id = extract_manga_id(mangadex_url)25        26        if manga_id:27            # Pass the extracted Manga ID to script.py28            result = subprocess.run(29                ["python", "script.py", manga_id], 30                capture_output=True, 31                text=True32            )33            output = result.stdout  # Capture the output of script.py34 35            # Return the output along with the Manga ID on the web page36            return f"""37            <h3>Manga ID: {manga_id}</h3>38            <pre>{output}</pre>39            <a href="/">Go back</a>40            """41        else:42            return """43            <h3>Invalid URL. Please try again!</h3>44            <a href="/">Go back</a>45            """46 47    # Render the form for the user to input the MangaDex URL48    return '''49    <form method="POST">50        <label for="url">Enter MangaDex URL:</label><br>51        <input type="url" id="url" name="url" placeholder="https://mangadex.org/title/..." required><br><br>52        <button type="submit">Submit</button>53    </form>54    '''55 56if __name__ == "__main__":57    # Run the Flask app on port 786058    app.run(host="0.0.0.0", port=7860)