def __delete_professions(professions: List[str], config: Config) -> Config: data = DataService(config) result = Config() result.load() prev = set(result.get_or_default("data.professions", [])) for prof in professions: pid, tid = data.find_profession_tier(prof) if pid is None: warning(f"Can't find profession {prof}... skipping") continue prev.remove(f"{pid}-{tid}") result["data.professions"] = list(prev) return result
def __delete_vendor_items(items: List[str], config: Config) -> Config: data = DataService(config) result = Config() result.load() prev = set(result.get_or_default("data.vendor_items", [])) for item in items: iid = data.find_item(item) if iid is None: warning(f"Can't find item {item}... skipping") continue prev.remove(iid) result["data.vendor_items"] = list(prev) return result
def __add_auction_items(items: List[str], config: Config, command: str) -> Config: data = DataService(config) result = Config() result.load() prev = set(result.get_or_default(f"auctions.{command}", [])) for item in items: iid = data.find_item(item) if iid is None: warning(f"Can't find item {item}... skipping") continue prev.add(iid) result[f"auctions.{command}"] = list(prev) return result
def find_auctions(self, keywords: List[str], datasvc: DataService, cache: Dict[int, Item]={}) -> List[Auction]: items = datasvc.get_items() matches = [i for i in items if all([kw.lower() in i.name.lower() for kw in keywords])] result = [] auctions = self.get_auctions() for m in matches: result.extend(auctions.get(m.id, [])) cache[m.id] = m return result
def __get_professions(prof_list: List[str], config: Config, data: DataService) -> Set[Tuple[int, int]]: result = set() for prof in prof_list: if prof == "config": for prof_tier in config.get_or_default("data.professions", []): pt = prof_tier.split("-") prof = int(pt[0]) tier = int(pt[1]) result.add((prof, tier)) else: result.add(data.find_profession_tier(prof)) return result
def handle_profit(args, config: Config, data: DataService, ah: AuctionHouse) -> int: professions: Set[Tuple[int, int]] = __get_professions(args.professions, config, data) vendor_items = __items_from_list_and_conf(args.vendor_items, "data.vendor_items", config, data) buy_items = __items_from_list_and_conf(args.buy, "auctions.buy", config, data) computer = RecipeCostComputer(config, data) computer.professions = [data.prof_tiers_by_id(prof_id, tier_id) for prof_id, tier_id in professions] computer.buy_items = buy_items computer.compute_baseline_prices(ah, vendor_items) computer.compute_production_costs() selling_price = computer.recipe_selling_price for recipe in sorted(computer.recipes, key=lambda recipe: not isinstance(recipe,NormalRecipe)): if recipe.id not in selling_price or recipe.id not in computer.recipe_production_costs: continue costs = computer.recipe_production_costs[recipe.id] price = selling_price[recipe.id] print_recipe(recipe, costs, price, computer)
def handle_auction_command(args, config: Config) -> int: ah = AuctionHouse(config) data = DataService(config) if args.subcommand == "update": info("Updating auction list...") ah.update(__get_connected_realm_id(config), __get_item_filter(config, data)) info("Auctionlist successfully updated") return 0 if args.update: info("Updating auction list...") ah.update(__get_connected_realm_id(config), __get_item_filter(config, data)) info("Auctionlist successfully updated") if args.subcommand == "search": item_cache: Dict[int, Item] = {} matches = ah.find_auctions(args.keywords, data, item_cache) for match in sorted(matches, key=lambda m: m.price): print_auction(match, item_cache) if args.subcommand == "profit": handle_profit(args, config, data, ah) return 0
def __get_item_ids(items: List[str], data: DataService) -> List[int]: if items is None: return [] return [data.find_item(itm) for itm in items]
def __get_item_filter(config: Config, data: DataService) -> Set[int]: return set([i.id for i in data.get_items()])
def __get_connected_realm_id(config) -> int: data = DataService(config) connected_realm_id, _ = data.find_realm(config["server.realm"]) return connected_realm_id