Skip to content

Commit

Permalink
Optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
siriiuss committed Apr 15, 2023
1 parent ec86cef commit 81a4b8b
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from fastapi import FastAPI, Response
from fastapi.responses import RedirectResponse
from fastapi import FastAPI, Response, HTTPException
from fastapi.responses import RedirectResponse, HTMLResponse
import json
import websockets

from time import sleep

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

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

teams = []
teams = [] # Tüm takımları saklayacak bir liste oluşturun

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

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

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

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

if data_type == "json_file":
return json_object
elif data_type == "live":
return teams
return teams


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

@app.get("/json")
async def json_type():
json_str = json.dumps(tff_data("json_file"), indent = 4, default = str, ensure_ascii=False)
return Response(content=json_str, media_type='application/json')
html = """
<!DOCTYPE html>
<html>
<head>
<title>Unavaible</title>
<meta http-equiv="refresh" content="10;URL='/live'" />
</head>
<body style="background-color: #121212;">
<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>
</p>
</body>
</html>
"""
return HTMLResponse(html)

@app.get("/live")
async def live():
Expand Down

0 comments on commit 81a4b8b

Please sign in to comment.