skip current day
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
0642e52d26
commit
c3492f2d49
9
main.py
9
main.py
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from os import path
|
from os import path
|
||||||
|
from datetime import datetime
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from query import ESQueryPeers
|
from query import ESQueryPeers
|
||||||
|
@ -59,8 +60,12 @@ def main():
|
||||||
|
|
||||||
peers = []
|
peers = []
|
||||||
for index in esq.get_indices(opts.index_pattern):
|
for index in esq.get_indices(opts.index_pattern):
|
||||||
|
# skip already injected indices
|
||||||
if index in present_indices:
|
if index in present_indices:
|
||||||
continue
|
continue
|
||||||
|
# skip current day as it's incomplete
|
||||||
|
if index == datetime.now().strftime('logstash-%Y.%m.%d'):
|
||||||
|
continue
|
||||||
print('Index: {}'.format(index))
|
print('Index: {}'.format(index))
|
||||||
peers.extend(esq.get_peers(index, opts.field, opts.max_size))
|
peers.extend(esq.get_peers(index, opts.field, opts.max_size))
|
||||||
|
|
||||||
|
@ -68,8 +73,8 @@ def main():
|
||||||
print('Nothing to insert into database.')
|
print('Nothing to insert into database.')
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
rval = psg.inject_peers(peers)
|
print('Injecting peers data into database...')
|
||||||
print(rval)
|
psg.inject_peers(peers)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
class PGDatabase:
|
class PGDatabase:
|
||||||
_SCHEMA = """
|
_SCHEMA = """
|
||||||
|
@ -21,10 +20,6 @@ class PGDatabase:
|
||||||
self.c.execute(self._SCHEMA)
|
self.c.execute(self._SCHEMA)
|
||||||
self.db.commit()
|
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):
|
def get_present_days(self):
|
||||||
self.c.execute('SELECT DISTINCT date FROM peers;')
|
self.c.execute('SELECT DISTINCT date FROM peers;')
|
||||||
return [d[0].strftime('%Y-%m-%d') for d in self.c.fetchall()]
|
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)
|
'INSERT INTO peers(date, peer, count) VALUES {}'.format(args)
|
||||||
)
|
)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
return rval
|
|
||||||
|
|
Loading…
Reference in New Issue