control commit

pull/1/head
Captain Arepa 2 years ago
parent 727f32db0a
commit 550b63d607

@ -72,18 +72,23 @@ class BotInstance:
print("Error: ", e)
return tunnel
def get_db_cursor(self, server):
# try:
server.start()
def get_db_cursor(self):
if self.use_ssh:
server = self.start_tunnel()
server.start()
port = server.local_bind_port
else:
port = self.db_port
params = {
'database': self.db_name,
'user': self.db_user,
'password': self.db_password,
'host': self.db_host,
'port': server.local_bind_port,
'port': port,
'cursor_factory': RealDictCursor
}
print("Server local port {0}", format(server.local_bind_port))
conn = psycopg2.connect(**params)
cursor = conn.cursor()
# except Exception as e:
@ -95,12 +100,9 @@ class BotInstance:
def get_all_blocks(self):
rows = None
try:
print("Get server tunnel...")
server = self.start_tunnel()
server.start()
print("Get DBconnection and cursor...")
conn, cursor = self.get_db_cursor(server)
conn, cursor = self.get_db_cursor()
sql = "select concat(that.username,'@',that.host ) as blocker, " \
"this.username as blockee, " \
@ -130,12 +132,9 @@ class BotInstance:
print("Get today's blocks")
rows = None
try:
print("Get server tunnel...")
server = self.start_tunnel()
server.start()
print("Get DBconnection and cursor...")
conn, cursor = self.get_db_cursor(server)
conn, cursor = self.get_db_cursor()
sql = "select concat(that.username,'@',that.host ) as blocker, " \
"this.username as blockee, " \
@ -166,12 +165,9 @@ class BotInstance:
print("Get this week's blocks")
rows = None
try:
print("Get server tunnel...")
server = self.start_tunnel()
server.start()
print("Get DBconnection and cursor...")
conn, cursor = self.get_db_cursor(server)
conn, cursor = self.get_db_cursor()
sql = "select concat(that.username,'@',that.host ) as blocker, " \
"this.username as blockee, " \
@ -202,12 +198,9 @@ class BotInstance:
print("Get this month's blocks")
rows = None
try:
print("Get server tunnel...")
server = self.start_tunnel()
server.start()
print("Get DBconnection and cursor...")
conn, cursor = self.get_db_cursor(server)
conn, cursor = self.get_db_cursor()
sql = "select concat(that.username,'@',that.host ) as blocker, " \
"this.username as blockee, " \
@ -238,12 +231,9 @@ class BotInstance:
print("Get latest block")
rows = None
try:
print("Get server tunnel...")
server = self.start_tunnel()
server.start()
print("Get DBconnection and cursor...")
conn, cursor = self.get_db_cursor(server)
conn, cursor = self.get_db_cursor()
sql = "select concat(that.username,'@',that.host ) as blocker, " \
"this.username as blockee, " \
@ -280,7 +270,7 @@ class BotInstance:
for row in result:
blocker = row["blocker"]
block_date = row["block_date"]
block_line += "%s%s (%s)\n" % (bullet, blocker, block_date)
block_line += "%s@%s (%s)\n" % (bullet, blocker, block_date)
return block_line

Loading…
Cancel
Save