from fastapi import FastAPI, File, UploadFile
from fastapi.responses import HTMLResponse
import csv
from typing import List
from io import StringIO
app = FastAPI()
url_counts = {}
api_counts = {}
url_names = {}
api_names = {}
@app.post("/upload/")
async def upload_csv(file: UploadFile):
if file.content_type == "text/csv":
content = await file.read()
content = content.decode('utf-8').splitlines()
total_records = 0
csvreader = csv.reader(content)
header = next(csvreader)
for row in csvreader:
url = row[3]
api = row[4]
url_name = row[2]
api_name = row[6]
total_records += 1
if url in url_counts:
url_counts[url] += 1
else:
url_counts[url] = 1
url_names[url] = url_name
if api in api_counts:
api_counts[api] += 1
else:
api_counts[api] = 1
api_names[api] = api_name
redundant_urls = [url for url, count in url_counts.items() if count > 1]
redundant_apis = [api for api, count in api_counts.items() if count > 1]
percentage_redundant_urls = (len(redundant_urls) / total_records) * 100 if total_records > 0 else 0
summary_string = f"Total GET Records: {total_records}
" \
f"% of Redundant GET Requests,you can save : {round(percentage_redundant_urls, 2)}%
"
html_table = "
GET Request | Count of Repetition |
---|---|
{url} | {count} |