Skip to content

Commit 81a4b8b

Browse files
committed
Optimized
1 parent ec86cef commit 81a4b8b

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

main.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from fastapi import FastAPI, Response
2-
from fastapi.responses import RedirectResponse
1+
from fastapi import FastAPI, Response, HTTPException
2+
from fastapi.responses import RedirectResponse, HTMLResponse
33
import json
4+
import websockets
5+
6+
from time import sleep
47

58
import requests
69
from bs4 import BeautifulSoup
@@ -14,7 +17,7 @@ def tff_data(data_type, url="https://www.tff.org/default.aspx?pageID=198"):
1417

1518
table = soup.find("table", {"class": "s-table"})
1619

17-
teams = []
20+
teams = [] # Tüm takımları saklayacak bir liste oluşturun
1821

1922
rows = table.findAll("tr")[1:]
2023

@@ -34,28 +37,31 @@ def tff_data(data_type, url="https://www.tff.org/default.aspx?pageID=198"):
3437
}
3538
teams.append(team_data)
3639

37-
with open("table.json", "w", encoding="utf-8") as f:
38-
json.dump(teams, f, ensure_ascii=False, indent=4)
39-
f.close()
4040

41-
with open('table.json', 'r', encoding="utf-8") as json_file:
42-
json_object = json.load(json_file)
4341

44-
if data_type == "json_file":
45-
return json_object
46-
elif data_type == "live":
47-
return teams
42+
return teams
4843

4944

5045
@app.get("/")
5146
async def root():
52-
json_str = json.dumps(tff_data("live"), indent = 4, default = str, ensure_ascii=False)
53-
return Response(content=json_str, media_type='application/json'
47+
return RedirectResponse("/live")
5448

5549
@app.get("/json")
5650
async def json_type():
57-
json_str = json.dumps(tff_data("json_file"), indent = 4, default = str, ensure_ascii=False)
58-
return Response(content=json_str, media_type='application/json')
51+
html = """
52+
<!DOCTYPE html>
53+
<html>
54+
<head>
55+
<title>Unavaible</title>
56+
<meta http-equiv="refresh" content="10;URL='/live'" />
57+
</head>
58+
<body style="background-color: #121212;">
59+
<p style="color: white; font-size: 14px;">The JSON type is unavailable due to system capacity issues. You will be redirected to Live in 10 seconds. For more detail <a href="" style="color: white;"> check documentation</a>
60+
</p>
61+
</body>
62+
</html>
63+
"""
64+
return HTMLResponse(html)
5965

6066
@app.get("/live")
6167
async def live():

0 commit comments

Comments
 (0)