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