from fastapi import FastAPI, Request, HTTPException, responses, Query
from fastapi.templating import Jinja2Templates
-from requests import get
from datetime import datetime
from email import utils
import uvicorn
+import requests
import sqlite3
import re
import fba
known, indexed, blocks = fba.c.fetchone()
return {
- "known_instances": known,
+ "known_instances" : known,
"indexed_instances": indexed,
- "blocks_recorded": blocks,
- "slogan": fba.config["slogan"]
+ "blocks_recorded" : blocks,
+ "slogan" : fba.config["slogan"]
}
@app.get(fba.config["base_url"] + "/top")
scores = fba.c.fetchall()
scoreboard = []
- print(scores)
+
for domain, highscore in scores:
scoreboard.append({"domain": domain, "highscore": highscore})
return result
@app.get(fba.config["base_url"] + "/scoreboard")
-def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None):
+def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, ):
scores = None
if blockers == None and blocked == None and reference == None:
raise HTTPException(status_code=400, detail="No filter specified")
elif blockers != None:
- scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}")
+ scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}")
elif blocked != None:
- scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
+ scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
elif reference != None:
- scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}")
-
- if scores != None:
- if not scores.ok:
- raise HTTPException(status_code=scores.status_code, detail=scores.text)
+ scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}")
- scores = scores.json()
+ if scores = None:
+ raise HTTPException(status_code=500, detail="Could not determine scores")
+ elif not scores.ok:
+ raise HTTPException(status_code=scores.status_code, detail=scores.text)
return templates.TemplateResponse("index.html", {
- "base_url": fba.config["base_url"],
- "request": request,
+ "base_url" : fba.config["base_url"],
+ "request" : request,
"scoreboard": True,
- "blockers": blockers,
- "blocked": blocked,
- "reference": reference,
- "scores": scores
+ "blockers" : blockers,
+ "blocked" : blocked,
+ "reference" : reference,
+ "scores" : scores.json()
})
@app.get(fba.config["base_url"] + "/")
blocks = None
if domain == None and reason == None and reverse == None:
- info = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/info")
+ info = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/info")
if not info.ok:
raise HTTPException(status_code=info.status_code, detail=info.text)
info = info.json()
elif domain != None:
- blocks = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?domain={domain}")
+ blocks = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?domain={domain}")
elif reason != None:
- blocks = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?reason={reason}")
+ blocks = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?reason={reason}")
elif reverse != None:
- blocks = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?reverse={reverse}")
+ blocks = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?reverse={reverse}")
if blocks != None:
if not blocks.ok: