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
3
3
import json
4
+ import websockets
5
+
6
+ from time import sleep
4
7
5
8
import requests
6
9
from bs4 import BeautifulSoup
@@ -14,7 +17,7 @@ def tff_data(data_type, url="https://www.tff.org/default.aspx?pageID=198"):
14
17
15
18
table = soup .find ("table" , {"class" : "s-table" })
16
19
17
- teams = []
20
+ teams = [] # Tüm takımları saklayacak bir liste oluşturun
18
21
19
22
rows = table .findAll ("tr" )[1 :]
20
23
@@ -34,28 +37,31 @@ def tff_data(data_type, url="https://www.tff.org/default.aspx?pageID=198"):
34
37
}
35
38
teams .append (team_data )
36
39
37
- with open ("table.json" , "w" , encoding = "utf-8" ) as f :
38
- json .dump (teams , f , ensure_ascii = False , indent = 4 )
39
- f .close ()
40
40
41
- with open ('table.json' , 'r' , encoding = "utf-8" ) as json_file :
42
- json_object = json .load (json_file )
43
41
44
- if data_type == "json_file" :
45
- return json_object
46
- elif data_type == "live" :
47
- return teams
42
+ return teams
48
43
49
44
50
45
@app .get ("/" )
51
46
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" )
54
48
55
49
@app .get ("/json" )
56
50
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 )
59
65
60
66
@app .get ("/live" )
61
67
async def live ():
0 commit comments