|
|
|
@ -13,8 +13,10 @@ import pdb
|
|
|
|
|
menu_options = {
|
|
|
|
|
1: 'New Bot',
|
|
|
|
|
2: 'Delete Bot',
|
|
|
|
|
3: 'List Bots',
|
|
|
|
|
4: 'Exit',
|
|
|
|
|
3: 'Activate Bot',
|
|
|
|
|
4: 'Deactivate Bot',
|
|
|
|
|
5: 'List Bots',
|
|
|
|
|
6: 'Exit',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def print_menu():
|
|
|
|
@ -264,6 +266,94 @@ class GetBot:
|
|
|
|
|
|
|
|
|
|
return (del_error)
|
|
|
|
|
|
|
|
|
|
def activate_account(self):
|
|
|
|
|
|
|
|
|
|
twitter_sql = 'SELECT bot_id from taccounts where username=(%s)'
|
|
|
|
|
|
|
|
|
|
activate_sql = 'update maccounts set active = True WHERE bot_id=(%s)'
|
|
|
|
|
|
|
|
|
|
conn = None
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
conn = psycopg2.connect(database = replicator_db, user = replicator_db_user, password = "", host = "/var/run/postgresql", port = "5432")
|
|
|
|
|
|
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
|
|
|
|
|
cur.execute(twitter_sql, (self.twitter_username,))
|
|
|
|
|
|
|
|
|
|
row = cur.fetchone()
|
|
|
|
|
|
|
|
|
|
if row != None:
|
|
|
|
|
|
|
|
|
|
cur.execute(activate_sql, (row[0],))
|
|
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
print(f'{self.twitter_username} had been activated')
|
|
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
print(f'{self.twitter_username} is not in the database')
|
|
|
|
|
|
|
|
|
|
except (Exception, psycopg2.DatabaseError) as error:
|
|
|
|
|
|
|
|
|
|
activate_error = error.pgcode
|
|
|
|
|
|
|
|
|
|
sys.stdout.write(f'\n{str(activate_error)}\n')
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
|
|
if conn is not None:
|
|
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
|
|
def deactivate_account(self):
|
|
|
|
|
|
|
|
|
|
twitter_sql = 'SELECT bot_id from taccounts where username=(%s)'
|
|
|
|
|
|
|
|
|
|
deactivate_sql = 'update maccounts set active = False WHERE bot_id=(%s)'
|
|
|
|
|
|
|
|
|
|
conn = None
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
conn = psycopg2.connect(database = replicator_db, user = replicator_db_user, password = "", host = "/var/run/postgresql", port = "5432")
|
|
|
|
|
|
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
|
|
|
|
|
cur.execute(twitter_sql, (self.twitter_username,))
|
|
|
|
|
|
|
|
|
|
row = cur.fetchone()
|
|
|
|
|
|
|
|
|
|
if row != None:
|
|
|
|
|
|
|
|
|
|
cur.execute(deactivate_sql, (row[0],))
|
|
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
print(f'{self.twitter_username} had been deactivated')
|
|
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
print(f'{self.twitter_username} is not in the database')
|
|
|
|
|
|
|
|
|
|
except (Exception, psycopg2.DatabaseError) as error:
|
|
|
|
|
|
|
|
|
|
activate_error = error.pgcode
|
|
|
|
|
|
|
|
|
|
sys.stdout.write(f'\n{str(activate_error)}\n')
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
|
|
if conn is not None:
|
|
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
|
|
def print(self):
|
|
|
|
|
|
|
|
|
|
print(f'\nBot found: {self.twitter_username}\n')
|
|
|
|
@ -296,7 +386,7 @@ def list_bots():
|
|
|
|
|
|
|
|
|
|
t_usernames_lst = []
|
|
|
|
|
|
|
|
|
|
mastodon_sql = 'SELECT bot_id, hostname, username, hostname_soft FROM maccounts'
|
|
|
|
|
mastodon_sql = 'SELECT bot_id, hostname, username, hostname_soft, active FROM maccounts'
|
|
|
|
|
|
|
|
|
|
twitter_sql = 'SELECT username from taccounts where bot_id=(%s)'
|
|
|
|
|
|
|
|
|
@ -430,17 +520,37 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
check_db_conn()
|
|
|
|
|
|
|
|
|
|
getbot = GetBot()
|
|
|
|
|
|
|
|
|
|
getbot.activate_account()
|
|
|
|
|
|
|
|
|
|
elif option == 4:
|
|
|
|
|
|
|
|
|
|
config_filepath, replicator_db, replicator_db_user = get_config()
|
|
|
|
|
|
|
|
|
|
check_db_conn()
|
|
|
|
|
|
|
|
|
|
getbot = GetBot()
|
|
|
|
|
|
|
|
|
|
getbot.deactivate_account()
|
|
|
|
|
|
|
|
|
|
elif option == 5:
|
|
|
|
|
|
|
|
|
|
config_filepath, replicator_db, replicator_db_user = get_config()
|
|
|
|
|
|
|
|
|
|
check_db_conn()
|
|
|
|
|
|
|
|
|
|
bots_list, t_usernames_lst = list_bots()
|
|
|
|
|
|
|
|
|
|
print_table = PrettyTable()
|
|
|
|
|
|
|
|
|
|
print_table.field_names = ['No.','Twitter username', 'bot account', 'host', 'host software']
|
|
|
|
|
print_table.field_names = ['No.','Twitter username', 'bot account', 'host', 'host software', 'active']
|
|
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
|
|
|
|
|
|
for bot in bots_list:
|
|
|
|
|
|
|
|
|
|
print_table.add_row([str(i+1), t_usernames_lst[i], bot[2], bot[1], bot[3]])
|
|
|
|
|
print_table.add_row([str(i+1), t_usernames_lst[i], bot[2], bot[1], bot[3], bot[4]])
|
|
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
|
@ -448,7 +558,7 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
print(f'Total: {len(bots_list)}')
|
|
|
|
|
|
|
|
|
|
elif option == 4:
|
|
|
|
|
elif option == 6:
|
|
|
|
|
|
|
|
|
|
print('Bye!')
|
|
|
|
|
exit()
|
|
|
|
|