|
|
@ -125,6 +125,124 @@ def get_all_blocks(config, mk_user):
|
|
|
|
return rows
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_todays_blocks(config, mk_user):
|
|
|
|
|
|
|
|
print("today's blocks!")
|
|
|
|
|
|
|
|
rows = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
print("Get server tunnel...")
|
|
|
|
|
|
|
|
server = start_tunnel(config)
|
|
|
|
|
|
|
|
server.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Get DBconnection and cursor...")
|
|
|
|
|
|
|
|
conn, cursor = get_db_cursor(config, server)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("SQL statement:\n")
|
|
|
|
|
|
|
|
sql = "select concat(that.username,'@',that.host ) as blocker, " \
|
|
|
|
|
|
|
|
"this.username as blockee, " \
|
|
|
|
|
|
|
|
"to_date(to_char(b.\"createdAt\", 'YYYY/MM/DD'), 'YYYY/MM/DD') as block_date " \
|
|
|
|
|
|
|
|
"from blocking b " \
|
|
|
|
|
|
|
|
"join \"user\" this on this.id = b.\"blockeeId\" " \
|
|
|
|
|
|
|
|
"join \"user\" that on that.id = b.\"blockerId\" " \
|
|
|
|
|
|
|
|
"where this.\"username\" like \'{0}\' " \
|
|
|
|
|
|
|
|
"and b.\"createdAt\" between current_date - interval '1 day' and current_date " \
|
|
|
|
|
|
|
|
"and this.host is null;".format(mk_user)
|
|
|
|
|
|
|
|
print(sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Execute SQL statement...")
|
|
|
|
|
|
|
|
cursor.execute(sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Fetch all!")
|
|
|
|
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Closing cursor...")
|
|
|
|
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Closing DB connection...")
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print("Error: ", e)
|
|
|
|
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_this_weeks_blocks(config, mk_user):
|
|
|
|
|
|
|
|
print("today's blocks!")
|
|
|
|
|
|
|
|
rows = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
print("Get server tunnel...")
|
|
|
|
|
|
|
|
server = start_tunnel(config)
|
|
|
|
|
|
|
|
server.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Get DBconnection and cursor...")
|
|
|
|
|
|
|
|
conn, cursor = get_db_cursor(config, server)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("SQL statement:\n")
|
|
|
|
|
|
|
|
sql = "select concat(that.username,'@',that.host ) as blocker, " \
|
|
|
|
|
|
|
|
"this.username as blockee, " \
|
|
|
|
|
|
|
|
"to_date(to_char(b.\"createdAt\", 'YYYY/MM/DD'), 'YYYY/MM/DD') as block_date " \
|
|
|
|
|
|
|
|
"from blocking b " \
|
|
|
|
|
|
|
|
"join \"user\" this on this.id = b.\"blockeeId\" " \
|
|
|
|
|
|
|
|
"join \"user\" that on that.id = b.\"blockerId\" " \
|
|
|
|
|
|
|
|
"where this.\"username\" like \'{0}\' " \
|
|
|
|
|
|
|
|
"and b.\"createdAt\" between current_date - interval '7 day' and current_date " \
|
|
|
|
|
|
|
|
"and this.host is null;".format(mk_user)
|
|
|
|
|
|
|
|
print(sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Execute SQL statement...")
|
|
|
|
|
|
|
|
cursor.execute(sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Fetch all!")
|
|
|
|
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Closing cursor...")
|
|
|
|
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Closing DB connection...")
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print("Error: ", e)
|
|
|
|
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_latest_block(config, mk_user):
|
|
|
|
|
|
|
|
print("today's blocks!")
|
|
|
|
|
|
|
|
rows = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
print("Get server tunnel...")
|
|
|
|
|
|
|
|
server = start_tunnel(config)
|
|
|
|
|
|
|
|
server.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Get DBconnection and cursor...")
|
|
|
|
|
|
|
|
conn, cursor = get_db_cursor(config, server)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("SQL statement:\n")
|
|
|
|
|
|
|
|
sql = "select concat(that.username,'@',that.host ) as blocker, " \
|
|
|
|
|
|
|
|
"this.username as blockee, " \
|
|
|
|
|
|
|
|
"to_date(to_char(b.\"createdAt\", 'YYYY/MM/DD'), 'YYYY/MM/DD') as block_date " \
|
|
|
|
|
|
|
|
"from blocking b " \
|
|
|
|
|
|
|
|
"join \"user\" this on this.id = b.\"blockeeId\" " \
|
|
|
|
|
|
|
|
"join \"user\" that on that.id = b.\"blockerId\" " \
|
|
|
|
|
|
|
|
"where this.\"username\" like \'{0}\' " \
|
|
|
|
|
|
|
|
"and this.host is null " \
|
|
|
|
|
|
|
|
"order by b.\"createdAt\" desc " \
|
|
|
|
|
|
|
|
"limit 1;".format(mk_user)
|
|
|
|
|
|
|
|
print(sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Execute SQL statement...")
|
|
|
|
|
|
|
|
cursor.execute(sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Fetch all!")
|
|
|
|
|
|
|
|
rows = cursor.fetchone()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Closing cursor...")
|
|
|
|
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Closing DB connection...")
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print("Error: ", e)
|
|
|
|
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_user_config():
|
|
|
|
def load_user_config():
|
|
|
|
print("user config!")
|
|
|
|
print("user config!")
|
|
|
|
config = None
|
|
|
|
config = None
|
|
|
@ -153,7 +271,7 @@ def main():
|
|
|
|
config = load_user_config()
|
|
|
|
config = load_user_config()
|
|
|
|
|
|
|
|
|
|
|
|
print("Getting all blocks...")
|
|
|
|
print("Getting all blocks...")
|
|
|
|
rows = get_all_blocks(config, "captain_arepa")
|
|
|
|
rows = get_latest_block(config, "captain_arepa")
|
|
|
|
print(rows)
|
|
|
|
print(rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|