Here's a Python program using the requests library to check the accessibility of websites and the Flask library to create an API for the desired user endpoints and admin statistics:
import time
import threading
from operator import itemgetter
import requests
from flask import Flask, jsonify
app = Flask(__name__)
sites = [
"http://google.com", "http://youtube.com", "http://facebook.com", "http://baidu.com",
"http://wikipedia.org", "http://qq.com", "http://taobao.com", "http://yahoo.com",
"http://tmall.com", "http://amazon.com", "http://google.co.in", "http://twitter.com",
"http://sohu.com", "http://jd.com", "http://live.com", "http://instagram.com",
"http://sina.com.cn", "http://weibo.com", "http://google.co.jp", "http://reddit.com",
"http://vk.com", "http://360.cn", "http://login.tmall.com", "http://blogspot.com",
"http://yandex.ru", "http://google.com.hk", "http://netflix.com", "http://linkedin.com",
"http://pornhub.com", "http://google.com.br", "http://twitch.tv", "http://pages.tmall.com",
"http://csdn.net", "http://yahoo.co.jp", "http://mail.ru", "http://aliexpress.com",
"http://alipay.com", "http://office.com", "http://google.fr", "http://google.ru",
"http://google.co.uk", "http://microsoftonline.com", "http://google.de", "http://ebay.com",
"http://microsoft.com", "http://livejasmin.com", "http://t.co", "http://bing.com",
"http://xvideos.com", "http://google.ca"]
access_times = {site: None for site in sites}
request_counts = {"endpoint-1": 0, "endpoint-2": 0, "endpoint-3": 0}
def check_sites():
while True:
for site in sites:
start_time = time.time()
try:
response = requests.head(site)
access_time = time.time() - start_time
access_times[site] = access_time
except requests.RequestException as e:
print(f"Error accessing {site}: {e}")
time.sleep(60)
@app.route("/access-time/<site>")
def get_access_time(site):
request_counts["endpoint-1"] += 1
access_time = access_times.get("http://" + site, "Site not found")
return jsonify({"site": site, "access_time": access_time})
@app.route("/min-access")
def get_min_access():
request_counts["endpoint-2"] += 1
min_site = min(access_times.items(), key=itemgetter(1))[0]
return jsonify({"min_site": min_site, "access_time": access_times[min_site]})
@app.route("/max-access")
def get_max_access():
request_counts["endpoint-3"] += 1
max_site = max(access_times.items(), key=itemgetter(1))[0]
return jsonify({"max_site": max_site, "access_time": access_times[max_site]})
@app.route("/admin/statistics")
def get_statistics():
return jsonify(request_counts)
if __name__ == "__main__":
update_thread = threading.Thread(target=check_sites)
update_thread.daemon = True
update_thread.start()
app.run(host="0.0.0.0", port=8000)
First, install the required libraries via pip:
pip install requests Flask
Run the program and access the following endpoints in your browser:
This program checks the sites every minute and updates the access times. Three user endpoints provide access times for a specific site, the site with the minimum access time, and the site with the maximum access time. The admin endpoint shows the number of requests made to each user endpoint.