diff options
author | nico <nico@magicbroccoli.de> | 2019-07-17 18:35:46 +0200 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2019-07-17 18:35:46 +0200 |
commit | 142c7db609a2b7e48105e6cbfd28c5385f83c705 (patch) | |
tree | f8721aa4ff8b6ec74d233a8eb49ca500e42344f4 /main.py | |
parent | 47e577ebaf07e4785a7a7cabfa402c36087fa1eb (diff) |
spam time-border
+ add time-borders to all queries
The JabberSpam manifesto states that the critical period for a server to be approved again is 14 days. Thus I adjusted all queries required for the report function to only count within these borders.
Though if a domain is specified without the report argument the time border is increased to 1 month to increase visibility.
misc:
+ add Codefactor badge
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -55,7 +55,8 @@ class AbuseReport: for domain in self.domain: sql_query = self.conn.execute('''SELECT COUNT(*) AS messages,COUNT(DISTINCT user) AS bots,domain, MIN(ts) - AS first,MAX(ts) AS last FROM spam WHERE domain = :domain;''',{"domain": domain}).fetchall() + AS first,MAX(ts) AS last FROM spam WHERE ts BETWEEN DATE('now','-1 months') AND DATE('now') + and domain = :domain;''',{"domain": domain}).fetchall() # if specified domain is not listed yet, the resulting table will not show the domain name # this ugly tuple 2 list swap prevents this @@ -76,8 +77,9 @@ class AbuseReport: if self.config.get_at("top10_view"): result = self.conn.execute('''SELECT * FROM "top10"''').fetchall() else: - result = self.conn.execute('''SELECT COUNT(*) AS messages,COUNT(DISTINCT user) AS bots,domain AS domain - FROM spam GROUP BY domain ORDER BY 1 DESC LIMIT 10''').fetchall() + result = self.conn.execute('''SELECT COUNT(*) AS messages, COUNT(DISTINCT user) AS bots, domain AS + domain FROM spam WHERE ts BETWEEN DATE('now','-14 days') AND DATE('now') GROUP BY domain + ORDER BY 1 DESC LIMIT 10;''').fetchall() # tabelize data spam_table = tabulate.tabulate(result, headers=["messages", "bots", "domain", "first seen", "last seen"], |