68 lines
2.7 KiB
Python
68 lines
2.7 KiB
Python
# There is a more efficient way of doing this, but i don't want to think about it rn
|
|
import time
|
|
import random
|
|
# from qwiklabs import create_account, delete_account
|
|
|
|
class QL_AccountList():
|
|
|
|
def __init__(self, account_list):
|
|
QL_AccountList.SUSPEND_TIME = 3600 #in seconds
|
|
QL_AccountList.ACTION_WAIT_TIME = 1200 #in seconds
|
|
|
|
self.account_list = account_list
|
|
self.suspended_list = {}
|
|
self.to_delete = []
|
|
self.last_action_time = time.time()
|
|
self.last_action = 0 #0 added, 1 removed
|
|
print("[QL_AccountList] New account list created! Using list from file: {} " .format(account_list))
|
|
|
|
def request_new_account(self):
|
|
with open(self.account_list, 'r') as accounts:
|
|
accounts_lines = []
|
|
#needed to strip down of \n
|
|
for line in accounts.readlines():
|
|
accounts_lines.append(line.rstrip())
|
|
|
|
while True:
|
|
account = accounts_lines[random.randint(0, len(accounts_lines)-1)]
|
|
if self.is_account_valid(account):
|
|
print("[QL_AccountList] A new account has been requested! choosen {}".format(account))
|
|
|
|
self.suspend_account(account)
|
|
return account
|
|
|
|
def suspend_account(self, account):
|
|
print("[QL_AccountList] Account {} will be suspended for the next {} seconds".format(account, QL_AccountList.SUSPEND_TIME))
|
|
self.suspended_list[account] = int(time.time())
|
|
|
|
def is_account_suspended(self, account):
|
|
return account in self.suspended_list.keys()
|
|
|
|
def is_account_valid(self, account):
|
|
return (not self.is_account_suspended(account)) and (not account in self.to_delete)
|
|
|
|
def mark_account_for_deletition(self):
|
|
print("[QL_AccountList] Account {} has been marked for deletition".format(account))
|
|
self.to_delete.append(account)
|
|
|
|
def update_account_list(self):
|
|
# Try to reintegrate suspended accounts
|
|
to_delete = []
|
|
for account in self.suspended_list.keys():
|
|
if time.time() - self.suspended_list[account] > QL_AccountList.SUSPEND_TIME:
|
|
to_delete.append(account)
|
|
|
|
for d in to_delete:
|
|
del self.suspended_list[d]
|
|
|
|
# if time.time() - self.last_action_time > QL_AccountList.ACTION_WAIT_TIME:
|
|
# # TODO: add the requesting of a proxy when doing these actions
|
|
|
|
# if last_action == 0:
|
|
# # removed an account from the "to delete" lsit
|
|
# delete_account.QL_DeleteAccount(False, to_delete[random.randint(0, len(to_delete)-1)])
|
|
# else:
|
|
# # otherwise create a new account
|
|
# create_account.QL_CreateAccount(False)
|
|
|