-import uvicorn
from fastapi import FastAPI, Request, HTTPException, responses, Query
-import sqlite3
from fastapi.templating import Jinja2Templates
from requests import get
from datetime import datetime
from email import utils
+
+import uvicorn
+import sqlite3
import re
import fba
if domain != None:
wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):])
punycode = domain.encode('idna').decode('utf-8')
- fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_added asc",
+ fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_added ASC",
(domain, "*." + domain, wildchar, fba.get_hash(domain), punycode, "*." + punycode))
elif reverse != None:
- fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocker = ? ORDER BY first_added asc", (reverse,))
+ fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocker = ? ORDER BY first_added ASC", (reverse,))
else:
- fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE reason like ? AND reason != '' ORDER BY first_added asc", ("%"+reason+"%",))
+ fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE reason like ? AND reason != '' ORDER BY first_added ASC", ("%"+reason+"%",))
blocks = fba.c.fetchall()
result = {}
for blocker, blocked, block_level, reason, first_added, last_seen in blocks:
- entry = {"blocker": blocker, "blocked": blocked, "reason": reason, "first_added": first_added, "last_seen": last_seen}
+ entry = {
+ "blocker": blocker,
+ "blocked": blocked,
+ "reason": reason,
+ "first_added": first_added,
+ "last_seen": last_seen
+ }
if block_level in result:
result[block_level].append(entry)
else:
else:
reason = "Provided reason: '" + reason + "'"
- result.append(
- {
+ result.append({
"blocker": blocker,
"blocked": blocked,
"block_level": block_level,
"reason": reason,
"first_added": first_added
- }
- )
+ })
timestamp = utils.format_datetime(datetime.now())
- return templates.TemplateResponse("rss.xml", {"request": request, "timestamp": timestamp, "domain": domain, "blocks": result}, headers={"Content-Type": "application/rss+xml"})
+ return templates.TemplateResponse("rss.xml", {
+ "request": request,
+ "timestamp": timestamp,
+ "domain": domain,
+ "blocks": result
+ }, headers={
+ "Content-Type": "application/rss+xml"
+ })
if __name__ == "__main__":
uvicorn.run("api:app", host="127.0.0.1", port=fba.config["port"], log_level=fba.config["log_level"])