MFF212 commited on
Commit
a49b336
·
1 Parent(s): c8e0891

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -12
main.py CHANGED
@@ -1,7 +1,6 @@
1
  from fastapi import FastAPI, File, UploadFile
2
  import csv
3
  from typing import List
4
- from io import TextIOWrapper
5
 
6
  app = FastAPI()
7
 
@@ -14,9 +13,11 @@ api_names = {}
14
  @app.post("/upload/")
15
  async def upload_csv(file: UploadFile):
16
  if file.content_type == "text/csv":
 
 
17
  total_records = 0
18
- csvfile = TextIOWrapper(file.file, encoding='utf-8')
19
- csvreader = csv.reader(csvfile)
20
  header = next(csvreader) # Skip the header row
21
  for row in csvreader:
22
  url = row[3] # Assuming the URL is in the 4th column (index 3)
@@ -48,15 +49,7 @@ async def upload_csv(file: UploadFile):
48
 
49
  return {
50
  "Total GET Records": total_records,
51
- "Redundant GET Requests": [
52
- {
53
- "URL": url,
54
- "Name": url_names[url],
55
- "Count": url_counts[url]
56
- }
57
- for url in redundant_urls
58
- ],
59
- "Percentage of Redundant GET Requests": round(percentage_redundant_urls, 2)
60
  }
61
  else:
62
  return {"error": "Invalid file format. Please upload a CSV file."}
 
1
  from fastapi import FastAPI, File, UploadFile
2
  import csv
3
  from typing import List
 
4
 
5
  app = FastAPI()
6
 
 
13
  @app.post("/upload/")
14
  async def upload_csv(file: UploadFile):
15
  if file.content_type == "text/csv":
16
+ content = await file.read()
17
+ content = content.decode('utf-8').splitlines()
18
  total_records = 0
19
+
20
+ csvreader = csv.reader(content)
21
  header = next(csvreader) # Skip the header row
22
  for row in csvreader:
23
  url = row[3] # Assuming the URL is in the 4th column (index 3)
 
49
 
50
  return {
51
  "Total GET Records": total_records,
52
+ "% of Redundant GET Requests": round(percentage_redundant_urls, 2)
 
 
 
 
 
 
 
 
53
  }
54
  else:
55
  return {"error": "Invalid file format. Please upload a CSV file."}