def find_price_or_quit(d, num_pages=3, good_price=450): min_price = 9000000 for i in range(num_pages): wait_loading(d) price_list = [] while len(price_list) == 0: price_list = r.retry(get_card_prices, 0.2, 0, d)[0] for price in price_list: if price < min_price: min_price = price if price < 400: return 0 if i != num_pages - 1: if not (r.retry(find_click_next_btn, 0.2, 4, d)[2]): break t.sleep(1) if min_price <= good_price: return min_price else: return min_price - calc_interval(min_price)
def find_click_login_btn(d): btn = d.find_elements_by_class_name("call-to-action") if len(btn) > 0: if "disabled" not in btn[0].get_attribute("class"): r.retry(btn[0].click, 0.1, 2) return "clicked_btn" else: return False return False
def sell_tradepile_players(d): expired_cards = r.retry(get_expired_cards, 0.5, 0, d)[0] wait_loading(d) while len(expired_cards) > 0: card = expired_cards[0] r.retry(card.click, 0.1, 0) sell_item(d) next_expired_cards_len = len(expired_cards) while next_expired_cards_len == len(expired_cards): next_expired_cards = r.retry(get_expired_cards, 0.5, 0, d)[0] next_expired_cards_len = len(next_expired_cards) expired_cards = next_expired_cards t.sleep(1) available_cards = r.retry(get_available_cards, 0, 0, d)[0] while len(available_cards) > 0: card = available_cards[0] r.retry(card.click, 0.1, 0) sell_item(d) next_available_cards_len = len(available_cards) while next_available_cards_len == len(available_cards): next_available_cards = r.retry(get_available_cards, 0.5, 0, d)[0] next_available_cards_len = len(next_available_cards) available_cards = next_available_cards
def input_name(d, player_name): player_name_box = d.find_element_by_class_name( "ut-player-search-control").find_element_by_xpath( ".//*[@placeholder='Digite o Nome do Jogador']") r.retry(player_name_box.send_keys, 0.02, 0, Keys.CONTROL + "a") r.retry(player_name_box.send_keys, 0.02, 0, Keys.DELETE) r.retry(player_name_box.send_keys, 0.02, 0, player_name) click_name_btn = r.retry(find_player_name_btn, 0.02, 0, d)[0] r.retry(click_name_btn.click, 0.02, 0)
def find_lowest_price(d, num_pages=3, good_price=600): min_price = 9000000 for i in range(num_pages): wait_loading(d) t.sleep(2) price_list = r.retry(get_card_prices, 0.2, 0, d)[0] for price in price_list: if price < min_price: min_price = price if i != num_pages - 1: if not (r.retry(find_click_next_btn, 0.2, 4, d)[2]): break if min_price <= good_price: return min_price else: return min_price - calc_interval(min_price)
def farm_bronze_packs(): web_driver = State.selenium_instance.get_web_driver() log = State.gui_instance.log_text while True: log([FarmBronzePackPage], "Going to store") r.retry(goto_store, 1, 0, web_driver) log([FarmBronzePackPage], "Going to packs") r.retry(goto_packs, 1, 0, web_driver) log([FarmBronzePackPage], "Going to bronze packs") r.retry(goto_bronze_packs, 0, 0, web_driver) log([FarmBronzePackPage], "Buying a bronze pack") r.retry(buy_base_bronze_pack, 0, 0, web_driver) r.retry(confirm_dialog, 0, 0, web_driver) time.sleep(8) log([FarmBronzePackPage], "Dealing with the items") deal_with_bronze_items(web_driver) time.sleep(5)
def manage_filter(self, d, counter, cur_filter): updated_filters = {} if self.alt_chem_styles != 0: if counter != 0 and counter % self.alt_chem_styles == 0: if cur_filter.chem_style: updated_filters["chem_style"] = ("Estilos Entrosam.", None) else: updated_filters["chem_style"] = ("Estilos Entrosam.", "BÁSICO") cur_min = get_min_price_textbox(d) if cur_min == self.target_min_price: self.min_price_direction = "up" elif cur_min == self.target_max_price - self._next_value( self.target_max_price, direction="down"): self.min_price_direction = "down" if self.min_price_direction == "up" and self.target_max_price != 200: r.retry(find_click_inc_min_price, 0.02, 0, d) elif self.min_price_direction == "down": r.retry(find_click_dec_min_price, 0.02, 0, d) cur_filter.update(d, **updated_filters)
def send(cls, event_type, namespace, manipulation, identifier, data_path_format_pairs): # write s3 file s3key = "{root}/{event_type}/{namespace}/{manipulation}/{identifier}-{hashcode}.avro".format( root=cls.ROOT, event_type=event_type, namespace=namespace, manipulation=manipulation, identifier=identifier, hashcode=datasign(data_path_format_pairs)) with Temp(s3key) as f: content = [] for path_, format_ in data_path_format_pairs: content.append({ "type": event_type, "namespace": namespace, "manipulation": manipulation, "identifier": identifier, "path": path_, "format": format_ }) write(cls.SCHEMA, f, content) retry(put, (cls.BUCKET, s3key, open(f.name, "rb")))
def check_status_buy(d, idx_sel_card): status = None # todo: cant stop thread while executing this while status is None: card_status = (d.find_element_by_class_name("paginated-item-list"). find_elements_by_class_name("rowContent")[idx_sel_card]. find_element_by_xpath("..").get_attribute("class")) if "won" in card_status: status = "won" if r.retry(negative_notification, 0.1, 2, d)[2]: status = "expired" return status
def deal_with_bronze_items(d): items = r.retry(find_item_list, 0.2, 0, d, [])[0] wait_loading(d) i = 0 while (len(items) > 0) and (i < len(items)): card = items[i] r.retry(card.click, 0.1, 0) if maybe_sell_item(d, card): t.sleep(2) items = r.retry(find_item_list, 0.2, 0, d, items)[0] else: t.sleep(0.5) i += 1 t.sleep(0.5) r.retry(sell_duplicates_if_present, 0.1, 4, d) r.retry(store_remaining_cards_if_present, 0.1, 4, d)
def sell_cards(): web_driver = State.selenium_instance.get_web_driver() log = State.gui_instance.log_text log([SellPage], "Going to transfers") r.retry(goto_transfers, 1, 0, web_driver) log([SellPage], "Going to tradepile") r.retry(goto_tradepile, 0, 0, web_driver) log([SellPage], "Removing sold cards") r.retry(remove_sold, 1, 3, web_driver) wait_loading(web_driver, 2) log([SellPage], "Selling cards") sell_tradepile_players(web_driver) log([SellPage], "All cards listed")
def buy_card(d, sell=True): _, fname, _ = r.retry_many([find_buy_btn, find_no_results], 0, 0, [[d], [d]]) if fname == "find_buy_btn": idx = r.retry(select_buy_card, 0, 0, d)[0] r.retry(find_click_buy_btn, 0, 0, d) r.retry(confirm_dialog, 0, 10, d) t.sleep(1.6) status = check_status_buy(d, idx) if status == "expired": t.sleep(0.5) return None else: if r.retry(negative_notification, 0.2, 1, d)[2]: t.sleep(0.5) return None bought_price = int( d.find_element_by_class_name("subContent").text.replace( ".", "")) t.sleep(0.5) if sell: sold_price = sell_item(d) t.sleep(0.5) return (bought_price, sold_price) else: if not already_in_club(d): send_player_to_club(d) t.sleep(0.5) return (bought_price, 0) else: sold_price = sell_item(d) t.sleep(0.5) return (bought_price, sold_price) elif fname == "find_no_results": wait_loading(d, 0) return
def sell_item(d): r.retry(find_click_cmp_btn, 0.1, 0, d) sell_price = find_lowest_price(d) r.retry(find_click_back_btn, 0.1, 0, d) t.sleep(0.5) r.retry(find_click_list_btn, 0.1, 0, d) wait_loading(d) t.sleep(0.2) # escreve preco min: 9000000 (default) init_price_box = ( d.find_element_by_class_name("ui-layout-right").find_element_by_xpath( ".//*[contains(text(), 'Inicial:')]").find_element_by_xpath(".."). find_element_by_xpath("..").find_element_by_class_name("numericInput")) t.sleep(0.15) r.retry(init_price_box.send_keys, 0.02, 0, Keys.CONTROL + "a") r.retry(init_price_box.send_keys, 0.02, 0, Keys.DELETE) t.sleep(0.2) r.retry(init_price_box.send_keys, 0.02, 0, "9000000") # escreve preco venda: min_price imm_price_box = ( d.find_element_by_class_name("ui-layout-right").find_element_by_xpath( ".//*[contains(text(), 'Imediato:')]").find_element_by_xpath(".."). find_element_by_xpath("..").find_element_by_class_name("numericInput")) t.sleep(0.15) r.retry(imm_price_box.send_keys, 0.02, 0, Keys.CONTROL + "a") r.retry(imm_price_box.send_keys, 0.02, 0, Keys.DELETE) t.sleep(0.2) r.retry(imm_price_box.send_keys, 0.02, 0, str(sell_price)) list_btn = d.find_element_by_class_name( "ui-layout-right" ).find_element_by_xpath( ".//*[contains(text(), 'Listar para') and not(contains(text(), 'novamente'))]" ) r.retry(list_btn.click, 0, 0) return sell_price
def select_playername_filter(d, name): fil = r.retry(find_playername_filter, 0.02, 0, d)[0] fil.send_keys(name) t.sleep(0.7) d.find_element_by_xpath(f"//*[contains(text(), '{name}')]").click()
def snipe( alt_chem_styles, name, quality, rarity, chem_style, league, position, nation, club, max_price, sell_player, ): counter = 0 tradepile_size = 0 max_tradepile_size = 100 cards_got = 0 total_spent = 0 total_earns = 0 web_driver = State.selenium_instance.get_web_driver() log_total_cards = State.gui_instance.update_total_cards log_total_profit = State.gui_instance.update_total_profit search_filter = Filter() controller = FilterController(alt_chem_styles=alt_chem_styles, target_max_price=max_price) r.retry(goto_transfers, 0, 0, web_driver) tradepile_size = r.retry(get_tradepile_size, 1, 0, web_driver)[0] r.retry(goto_transfer_search, 0, 0, web_driver) r.retry( find_click_reset_filter_btn, 0, 0, web_driver, ) search_filter.update( web_driver, name=("Name", name), quality=("Qualidade", quality), rarity=("Raridade", rarity), chem_style=("Estilos Entrosam.", chem_style), league=("Liga", league), position=("Posição", position), nation=("Nacionalidade", nation), club=("Clube", club), max_price=("Máx.:", max_price), ) while tradepile_size < max_tradepile_size: r.retry(confirm_search, 0, 0, web_driver) if sell_player == 1: result = buy_card(web_driver, sell=False) else: result = buy_card(web_driver, sell=True) if counter > 0 and counter % 25 == 0: time.sleep(5) if result: cards_got += 1 total_spent += result[0] total_earns += result[1] * 0.95 if result[1] * 0.95 - result[0] > 0: tradepile_size += 1 log_total_cards([SnipePage], f"{str(cards_got)}") log_total_profit([SnipePage], f"{str(int(total_earns-total_spent))}") r.retry(back_transfer_search, 0, 0, web_driver) controller.manage_filter(web_driver, counter, search_filter) counter += 1
def get_min_price_textbox(d): fil = r.retry(find_textbox_filter, 0.02, 0, d, "Mín.:")[0].get_attribute("value") return int(fil.replace(".", "")) if fil != "" else 0
def select_filter(d, filter_name="", value=""): r.retry(find_click_filter, 0.02, 0, d, filter_name) r.retry( d.find_element_by_xpath(f"//*[contains(text(), '{value}')]").click, 0.02, 0)
def select_textbox_filter(d, filter_name="", value=""): fil = r.retry(find_textbox_filter, 0.02, 0, d, filter_name)[0] r.retry(fil.send_keys, 0.02, 0, str(value))
def maybe_sell_item(d, card): coin_card, _, exists = r.retry(d.find_element_by_xpath, 0.2, 0.7, "//*[contains(text(), 'Resgatar ')]") if exists: t.sleep(1.5) coin_card.find_element_by_xpath("..").click() t.sleep(1.5) return False if not is_player(card): return False r.retry(find_click_cmp_btn, 0.1, 0, d) sell_price = find_price_or_quit(d) if sell_price == 0: return False r.retry(find_click_back_btn, 0.1, 0, d) t.sleep(0.5) r.retry(find_click_list_btn, 0.1, 0, d) wait_loading(d) t.sleep(0.2) # escreve preco min: 9000000 (default) init_price_box = ( d.find_element_by_class_name("ui-layout-right").find_element_by_xpath( ".//*[contains(text(), 'Inicial:')]").find_element_by_xpath(".."). find_element_by_xpath("..").find_element_by_class_name("numericInput")) t.sleep(0.15) r.retry(init_price_box.send_keys, 0.02, 0, Keys.CONTROL + "a") r.retry(init_price_box.send_keys, 0.02, 0, Keys.DELETE) t.sleep(0.2) r.retry(init_price_box.send_keys, 0.02, 0, "9000000") # escreve preco venda: min_price imm_price_box = ( d.find_element_by_class_name("ui-layout-right").find_element_by_xpath( ".//*[contains(text(), 'Imediato:')]").find_element_by_xpath(".."). find_element_by_xpath("..").find_element_by_class_name("numericInput")) t.sleep(0.15) r.retry(imm_price_box.send_keys, 0.02, 0, Keys.CONTROL + "a") r.retry(imm_price_box.send_keys, 0.02, 0, Keys.DELETE) t.sleep(0.2) r.retry(imm_price_box.send_keys, 0.02, 0, str(sell_price)) list_btn = d.find_element_by_class_name( "ui-layout-right" ).find_element_by_xpath( ".//*[contains(text(), 'Listar para') and not(contains(text(), 'novamente'))]" ) r.retry(list_btn.click, 0, 0) return sell_price