Fill dates without spam attempts with zeros

This commit is contained in:
spla 2022-01-19 14:12:25 +01:00
pare e929ea2526
commit e6bbafefc7

Veure arxiu

@ -1,4 +1,4 @@
import datetime from datetime import datetime, timedelta
from mastodon import Mastodon from mastodon import Mastodon
import time import time
import os import os
@ -15,6 +15,8 @@ def write_totals(spamcheck_datetime_lst, spamcheck_registers_lst):
insert_sql = 'INSERT INTO totals(datetime, registers) VALUES(%s,%s) ON CONFLICT (datetime) DO UPDATE SET (datetime, registers) = (EXCLUDED.datetime, EXCLUDED.registers)' insert_sql = 'INSERT INTO totals(datetime, registers) VALUES(%s,%s) ON CONFLICT (datetime) DO UPDATE SET (datetime, registers) = (EXCLUDED.datetime, EXCLUDED.registers)'
first_date = spamcheck_datetime_lst[0]
i = 0 i = 0
while i < len(spamcheck_datetime_lst): while i < len(spamcheck_datetime_lst):
@ -27,7 +29,15 @@ def write_totals(spamcheck_datetime_lst, spamcheck_registers_lst):
cur = conn.cursor() cur = conn.cursor()
cur.execute(insert_sql, (spamcheck_datetime_lst[i], spamcheck_registers_lst[i])) if first_date == spamcheck_datetime_lst[i]:
cur.execute(insert_sql, (spamcheck_datetime_lst[i], spamcheck_registers_lst[i]))
i += 1
else:
cur.execute(insert_sql, (first_date, '0'))
conn.commit() conn.commit()
@ -43,7 +53,7 @@ def write_totals(spamcheck_datetime_lst, spamcheck_registers_lst):
conn.close() conn.close()
i += 1 first_date = first_date + timedelta(days=1)
def get_totals(): def get_totals():