Fill dates without spam attempts with zeros
This commit is contained in:
parent
e929ea2526
commit
e6bbafefc7
1 changed files with 13 additions and 3 deletions
16
spamcheck.py
16
spamcheck.py
|
@ -1,4 +1,4 @@
|
|||
import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from mastodon import Mastodon
|
||||
import time
|
||||
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)'
|
||||
|
||||
first_date = spamcheck_datetime_lst[0]
|
||||
|
||||
i = 0
|
||||
|
||||
while i < len(spamcheck_datetime_lst):
|
||||
|
@ -27,7 +29,15 @@ def write_totals(spamcheck_datetime_lst, spamcheck_registers_lst):
|
|||
|
||||
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()
|
||||
|
||||
|
@ -43,7 +53,7 @@ def write_totals(spamcheck_datetime_lst, spamcheck_registers_lst):
|
|||
|
||||
conn.close()
|
||||
|
||||
i += 1
|
||||
first_date = first_date + timedelta(days=1)
|
||||
|
||||
def get_totals():
|
||||
|
||||
|
|
Loading…
Reference in a new issue