mirror of
https://github.com/r4sas/Niflheim-api
synced 2025-01-26 06:34:14 +00:00
rewritten for use with postgresql
This commit is contained in:
parent
87afec4a6d
commit
ff423a7714
@ -1,39 +1,43 @@
|
|||||||
#add current node count to timeseries table
|
#max/min for the day with nodes
|
||||||
#can later be used to plot a graph showing daily max nodes on the network
|
import psycopg2
|
||||||
#run every hour
|
|
||||||
|
|
||||||
import sqlite3
|
|
||||||
from sqlite3 import Error
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
DB_PATH = "vservdb/"
|
#run every hour
|
||||||
|
|
||||||
|
DB_PASSWORD = "password"
|
||||||
|
DB_USER = "yggindex"
|
||||||
|
DB_NAME = "yggindex"
|
||||||
|
DB_HOST = "localhost"
|
||||||
|
|
||||||
def age_calc(ustamp):
|
def age_calc(ustamp):
|
||||||
if (time.time() - ustamp) <= 14400 :
|
if (time.time() - ustamp) <= 14400 :
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_nodes_for_count():
|
||||||
|
dbconn = psycopg2.connect(host=DB_HOST,database=DB_NAME, user=DB_USER, password=DB_PASSWORD)
|
||||||
|
cur = dbconn.cursor()
|
||||||
|
nodes = {}
|
||||||
|
cur.execute("select * from yggindex")
|
||||||
|
|
||||||
|
for i in cur.fetchall():
|
||||||
|
if age_calc(int(i[2])):
|
||||||
|
nodes[i[0]] = [i[1],int(i[2])]
|
||||||
|
|
||||||
|
cur.close()
|
||||||
|
dbconn.close()
|
||||||
|
|
||||||
def get_nodes_for_count(db_path):
|
|
||||||
conn = sqlite3.connect(db_path + 'yggindex.db')
|
|
||||||
query = conn.execute("select * from yggindex")
|
|
||||||
nodes = []
|
|
||||||
for i in query.fetchall():
|
|
||||||
if age_calc(i[2]):
|
|
||||||
nodes.append(i[1])
|
|
||||||
return str(len(nodes))
|
return str(len(nodes))
|
||||||
|
|
||||||
|
def add_to_db():
|
||||||
|
dbconn = psycopg2.connect(host=DB_HOST,database=DB_NAME, user=DB_USER, password=DB_PASSWORD)
|
||||||
|
cur = dbconn.cursor()
|
||||||
|
|
||||||
def add_to_timeseries(db_path):
|
cur.execute('''INSERT INTO timeseries(max, unixtstamp) VALUES(''' + "'" + get_nodes_for_count() + "'," + str(int(time.time())) + ''')''')
|
||||||
# try:
|
|
||||||
conn = sqlite3.connect(db_path + "yggindex.db")
|
|
||||||
c = conn.cursor()
|
|
||||||
c.execute('''INSERT INTO timeseries(max) VALUES(''' + "'"\
|
|
||||||
+ get_nodes_for_count(db_path) + "'" + ''')''')
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
|
dbconn.commit()
|
||||||
|
cur.close()
|
||||||
|
dbconn.close()
|
||||||
|
|
||||||
add_to_timeseries(DB_PATH)
|
add_to_db()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user