Fill today's totals with zero if any attempt

master
spla 1 year ago
parent e6bbafefc7
commit a7113472a6

@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import date, datetime, timedelta
from mastodon import Mastodon
import time
import os
@ -17,6 +17,8 @@ def write_totals(spamcheck_datetime_lst, spamcheck_registers_lst):
first_date = spamcheck_datetime_lst[0]
last_date = spamcheck_datetime_lst[len(spamcheck_datetime_lst)-1]
i = 0
while i < len(spamcheck_datetime_lst):
@ -55,6 +57,34 @@ def write_totals(spamcheck_datetime_lst, spamcheck_registers_lst):
first_date = first_date + timedelta(days=1)
if date.today() == last_date + timedelta(days=1):
insert_sql = 'INSERT INTO totals(datetime, registers) VALUES(%s,%s) ON CONFLICT (datetime) DO UPDATE SET (datetime, registers) = (EXCLUDED.datetime, EXCLUDED.registers)'
conn = None
try:
conn = psycopg2.connect(database = spamcheck_db, user = spamcheck_db_user, password = "", host = "/var/run/postgresql", port = "5432")
cur = conn.cursor()
cur.execute(insert_sql, (date.today(), '0'))
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
def get_totals():
spamcheck_datetime_lst = []
@ -285,7 +315,7 @@ if __name__ == '__main__':
while i < len(id_lst):
if detect(text_lst[i]) != 'ca':
if detect(text_lst[i]) != 'ca' or len(text_lst) == 1:
is_tor_exit_node = check_ip(ip_lst[i])

Loading…
Cancel
Save