aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Herkt <lachs0r@srsfckn.biz>2017-10-27 08:52:45 +0200
committerMartin Herkt <lachs0r@srsfckn.biz>2017-10-27 08:53:19 +0200
commitc3c29ab500b9ccf3a0cd1031df026337e4c2b1f9 (patch)
treeb79fb585b67e255cb97c5dac38709475df287931
parentAdd NSFW filter to address query commands (diff)
downloadhex-zero-c3c29ab500b9ccf3a0cd1031df026337e4c2b1f9.tar.gz
hex-zero-c3c29ab500b9ccf3a0cd1031df026337e4c2b1f9.tar.bz2
hex-zero-c3c29ab500b9ccf3a0cd1031df026337e4c2b1f9.zip
Faster query commands, add removed query filter
-rwxr-xr-xfhost.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/fhost.py b/fhost.py
index 920ad5e..a181138 100755
--- a/fhost.py
+++ b/fhost.py
@@ -109,6 +109,14 @@ class File(db.Model):
else:
return url_for("get", path=n, _external=True) + "\n"
+ def pprint(self):
+ print("url: {}".format(self.getname()))
+ vals = vars(self)
+
+ for v in vals:
+ if not v.startswith("_sa"):
+ print("{}: {}".format(v, vals[v]))
+
def getpath(fn):
return os.path.join(app.config["FHOST_STORAGE_PATH"], fn)
@@ -445,28 +453,27 @@ def query(name):
f = File.query.get(id)
if f:
- print("url: {}".format(f.getname()))
- vals = vars(f)
-
- for v in vals:
- if not v.startswith("_sa"):
- print("{}: {}".format(v, vals[v]))
+ f.pprint()
@manager.command
def queryhash(h):
f = File.query.filter_by(sha256=h).first()
+
if f:
- query(su.enbase(f.id, 1))
+ f.pprint()
@manager.command
-def queryaddr(a, nsfw=False):
+def queryaddr(a, nsfw=False, removed=False):
res = File.query.filter_by(addr=a)
+ if not removed:
+ res = res.filter(File.removed != True)
+
if nsfw:
res = res.filter(File.nsfw_score > app.config["NSFW_THRESHOLD"])
for f in res:
- query(su.enbase(f.id, 1))
+ f.pprint()
def nsfw_detect(f):
try:
@@ -500,15 +507,27 @@ def update_nsfw():
@manager.command
-def querybl(nsfw=False):
+def querybl(nsfw=False, removed=False):
+ blist = []
if os.path.isfile(app.config["FHOST_UPLOAD_BLACKLIST"]):
with open(app.config["FHOST_UPLOAD_BLACKLIST"], "r") as bl:
for l in bl.readlines():
if not l.startswith("#"):
if not ":" in l:
- queryaddr("::ffff:" + l.rstrip(), nsfw)
+ blist.append("::ffff:" + l.rstrip())
else:
- queryaddr(l.strip(), nsfw)
+ blist.append(l.strip())
+
+ res = File.query.filter(File.addr.in_(blist))
+
+ if not removed:
+ res = res.filter(File.removed != True)
+
+ if nsfw:
+ res = res.filter(File.nsfw_score > app.config["NSFW_THRESHOLD"])
+
+ for f in res:
+ f.pprint()
if __name__ == "__main__":
manager.run()
bgstack15