def action(self, type, **kwargs): # TODO change spaghetti code to something else result = {'type': '', 'response': ''} if type == ACTIONS_TYPES.get('register'): result = register(self.s, self.login, self.password) if type == ACTIONS_TYPES.get('exit'): result = sign_out(self.s) if type == ACTIONS_TYPES.get('open'): result = open_page(self.s, kwargs['open_type']) if type == ACTIONS_TYPES.get('vote'): result = vote_action(self.s) if type == ACTIONS_TYPES.get('download'): result = download_action(self.s) self.results.append(result)
def iter_bot(request): global bot_process print('bot_process', bot_process) response = {'status': 'failed'} if request.is_ajax() and bot_process: id_array = request.session['id_array'] bot_id = id_array.pop(0) account = get_object_or_404(Account, id=bot_id) bot = Bot(account.login, account.password) perform_action(bot, ACTIONS_TYPES.get('open'), open_type=OPEN_TYPES.get('board')) perform_action(bot, ACTIONS_TYPES.get('vote')) perform_action(bot, ACTIONS_TYPES.get('download')) print(bot.get_results()) request.session['id_array'] = id_array if len(id_array) == 0: bot_process = False response['status'] = 'success' response['results'] = bot.get_results() return json.dumps(response)
def __init__(self, login, password): self.s = requests.Session() self.login = login self.password = password self.results = [] self.action(ACTIONS_TYPES.get('register'))
def __del__(self): self.action(ACTIONS_TYPES.get('exit')) self.s.close()