skip current day

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-07-14 12:08:17 +02:00
parent 0642e52d26
commit c3492f2d49
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
2 changed files with 7 additions and 8 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3
from os import path
from datetime import datetime
from optparse import OptionParser
from query import ESQueryPeers
@ -59,8 +60,12 @@ def main():
peers = []
for index in esq.get_indices(opts.index_pattern):
# skip already injected indices
if index in present_indices:
continue
# skip current day as it's incomplete
if index == datetime.now().strftime('logstash-%Y.%m.%d'):
continue
print('Index: {}'.format(index))
peers.extend(esq.get_peers(index, opts.field, opts.max_size))
@ -68,8 +73,8 @@ def main():
print('Nothing to insert into database.')
exit(0)
rval = psg.inject_peers(peers)
print(rval)
print('Injecting peers data into database...')
psg.inject_peers(peers)
if __name__ == '__main__':
main()

View File

@ -1,5 +1,4 @@
import psycopg2
from datetime import datetime
class PGDatabase:
_SCHEMA = """
@ -21,10 +20,6 @@ class PGDatabase:
self.c.execute(self._SCHEMA)
self.db.commit()
def get_last_day(self):
self.c.execute('SELECT date FROM peers ORDER BY date DESC LIMIT 1;')
return self.c.fetchone()
def get_present_days(self):
self.c.execute('SELECT DISTINCT date FROM peers;')
return [d[0].strftime('%Y-%m-%d') for d in self.c.fetchall()]
@ -38,4 +33,3 @@ class PGDatabase:
'INSERT INTO peers(date, peer, count) VALUES {}'.format(args)
)
self.db.commit()
return rval