File size: 535 Bytes
5ca73ce
 
 
 
 
 
eeaf651
1c2d839
5ca73ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, request, jsonify
import random

app = Flask(__name__)

URLS = [
    "https://science.yangplace.qzz.io",
    "http://10.14.0.145:8080",
]


@app.route("/")
def get_url():
    failed = request.args.get("failed")

    urls = URLS.copy()

    if not urls:
        return jsonify({"error": "URL list is empty"})

    if failed:
        urls = [u for u in urls if u != failed]

    if not urls:
        return jsonify({"error": "No URLs remaining after filtering"})

    return jsonify({"url": random.choice(urls)})