Пример #1
0
def getItems(url, limit=0):
    '''
    从数据库查询
    :param url:
    :param limit 支持倒数
    :return: item []
    '''
    items = []
    url = trimUrl(url)
    if url:
        db = pymysql.connect(config.database_config['host'],
                             config.database_config['user'],
                             config.database_config['passwd'],
                             config.database_config['db_name'])
        cursor = db.cursor()
        ext = ""
        if limit:
            order = ""
            if limit < 0:
                order = "desc"
            ext = " order by date " + order + " limit " + str(abs(limit))
        sql = "select * from item where url = '" + url + "'" + ext
        print("database.getItems >> " + sql)
        try:
            cursor.execute(sql)
            results = cursor.fetchall()
            for row in results:
                item = Item(row[1], row[2], row[3], row[4])
                item.id = row[0]
                item.date = row[5]
                items.append(item)
        except:
            print("database.getItems >> Error: unable to fetch data")
        db.close()
    return items
Пример #2
0
 def read_single_goods_item(self, element: WebElement) \
         -> (Item, None):
     """
     :param element:
         A item of the list witch gain by method: get_goods_list().
     :return:
         An instance of Item or None, if an error occurred.
     """
     item = Item()
     # 起止时间
     item.data_begin_time = time.time()
     # 获取颜色标题及所选项目值(详情列表不存在的)
     # 获取版本标题及所选项目值(详情列表不存在的)
     # 获取商品url
     item.url = self.get_item_url(element)
     # 获取价格
     item.price = self.get_price(element)
     if item.price == -1:
         logging.warning("JdListPageReader:Get price is -1\n" + item.url)
         return None
     # 获取plus会员价格(详情列表不存在的)
     # 领券(详情列表不存在的)
     # 库存:京东不显示库存量,只有有无货之分(详情列表不存在的)
     # 快递费:京东各省价格均不同,有货情况也不同故不做记录(详情列表不存在的)
     # 销量
     item.sales_amount = self.get_sales_amount(element)
     # 可选字段(详情列表不存在的)
     # 生成所有字段(详情列表不存在的)
     item.generate_all_specification()
     return item
Пример #3
0
    def load_data(self, file_name):
        """
        Loads data from given file

        :param file_name: str
            Name of data file
        """
        data_path = Engine.DATA_DIR + file_name
        with open(data_path) as f:
            lines = list(f)

        self.problem_name = lines[0].split(':')[1].replace('\t', '').replace(
            '\n', '')
        self.knapsack_data_type = lines[1].split(':')[1].replace('\t',
                                                                 '').replace(
            '\n', '')
        self.nodes_num = int(lines[2].split(':')[1].replace('\t', '').replace(
            '\n', ''))
        self.items_num = int(lines[3].split(':')[1].replace('\t', '').replace(
            '\n', ''))
        self.max_capacity = int(lines[4].split(':')[1].replace('\t',
                                                               '').replace(
            '\n', ''))
        self.min_speed = float(lines[5].split(':')[1].replace('\t',
                                                              '').replace(
            '\n', ''))
        self.max_speed = float(lines[6].split(':')[1].replace('\t',
                                                              '').replace(
            '\n', ''))
        self.renting_ratio = float(lines[7].split(':')[1].replace(
            '\t', '').replace('\n', ''))
        self.edge_weight_type = lines[8].split(':')[1].replace('\t',
                                                               '').replace(
            '\n', '')

        node_lines = lines[10:self.nodes_num + 10]
        item_lines = lines[self.nodes_num + 11:self.nodes_num +
                                               self.items_num + 11]

        for node_line in node_lines:
            _, x, y = node_line.split()

            node = Node(float(x), float(y))
            self.nodes.append(node)

        for item_line in item_lines:
            _, profit, weight, node = item_line.split()

            item = Item(int(profit), int(weight))

            if self.items is not None:
                self.items.append(item)

            node_id = int(node) - 1
            self.nodes[node_id].add_item(item)
Пример #4
0
def captureTaobaoItem(url):
    '''网络获取'''
    res = requests.get(url)
    soup = BeautifulSoup(res.text, features='html.parser')
    # title
    title = soup.find('h3', class_='tb-main-title').attrs['data-title'].strip()
    print("spider.captureTaobaoItem >> "+title)
    # price
    price = soup.find('em', class_='tb-rmb-num').text.strip()
    print("spider.captureTaobaoItem >> "+price)
    print("spider.captureTaobaoItem >> "+url)
    item = Item(url, title, 0, 0)
    pattern = re.compile("[\d\.]+")
    match = pattern.findall(price)
    if match:
        item.min_price = match[0]
        if len(match)>1:
            item.max_price = match[1]
    return item
Пример #5
0
              fighter=Fighter(hp=10, defense=0, power=3),
              inventory=Inventory(capacity=0),
              level=Level(xp_given=50))
juggernaut = Actor(
    char="T",
    color=(0, 127, 0),
    name="juggernaut",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=16, defense=1, power=4),
    inventory=Inventory(capacity=0),
    level=Level(xp_given=100),
)

med_kit = Item(
    char="+",
    color=(127, 0, 255),
    name="med kit",
    consumable=consumable.HealingConsumable(amount=15),
)

bowie_knife = Item(
    char="~",
    color=(255, 255, 0),
    name="throwing knife",
    consumable=consumable.KnifeDamageConsumable(damage=20, maximum_range=5),
)

flashbang = Item(char="=",
                 color=(207, 63, 255),
                 name="flashbang",
                 consumable=consumable.ConfusionConsumable(
                     number_of_turns=10, ))
Пример #6
0
            strength=16,
            dexterity=12)

troll = Actor(char="T",
              color=(0, 127, 0),
              name="Troll",
              ai_cls=HostileEnemy,
              equipment=Equipment(),
              fighter=Fighter(hp=16),
              inventory=Inventory(capacity=0),
              level=Level(xp_given=100),
              strength=15)

health_potion = Item(
    char="!",
    color=(127, 0, 255),
    name="Potion of Healing",
    consumable=consumable.HealingConsumable(die=4, number_of_dice=2, bonus=2),
)
confusion_scroll = Item(
    char="~",
    color=(207, 63, 255),
    name="Confusion Scroll",
    consumable=consumable.ConfusionConsumable(number_of_turns=10),
)
fireball_scroll = Item(
    char="~",
    color=(255, 0, 0),
    name="Fireball Scroll",
    consumable=consumable.FireballDamageConsumable(damage=12, radius=3),
)
lightning_scroll = Item(
Пример #7
0
    level=Level(xp_given=35),
)
TROLL = Actor(
    char="T",
    color=(0, 127, 0),
    name="Troll",
    ai_cls=HostileEnemy,
    equipment=Equipment(),
    fighter=Fighter(hp=16, base_defense=1, base_power=4),
    inventory=Inventory(capacity=0),
    level=Level(xp_given=100),
)

DAGGER = Item(char="/",
              color=(0, 191, 255),
              name="Dagger",
              stackable=False,
              equippable=Dagger())
SWORD = Item(char="/",
             color=(0, 191, 255),
             name="Sword",
             stackable=False,
             equippable=Sword())
LEATHER_ARMOR = Item(
    char="[",
    color=(139, 69, 19),
    name="Leather Armor",
    stackable=False,
    equippable=LeatherArmor(),
)
CHAIN_MAIL = Item(
def instanceLoader(entityType, entityName):

    if entityType == "item":

        # check if item exists
        if itemCheck(entityName, "ITEMFOUND"):

            # open file where item is located
            with open(itemCheck(entityName, "ITEMLOCATION"), "r") as file:
                reader = csv.reader(file, delimiter=',')

                # search each row to find item
                for row in reader:
                    if row[0] == entityName:
                        # create, initialize, and return the item found
                        item = Item(entityName, row[1], row[2], row[3], row[4],
                                    row[5], row[6])
                        return item
        else:
            print("{} does not exist".format(entityName))
            sys.exit(2)

    # ensure csv file exists
    if os.path.isfile("entity_data/" + entityType + ".csv" == False):
        print(
            "{} data does not exist. Please restart and create a new {} data file."
            .format(entityType.capitalize(), entityType.capitalize()))
        sys.exit(3)

    with open("entity_data/" + entityType + ".csv", "r") as file:
        reader = csv.reader(file, delimiter=',')
        # search every first value until name is found
        for name in reader:
            if entityName == name[0]:
                # create a new entity with values found in csv file
                if entityType == "player":
                    # intialize a player with default values
                    # Class: Human, Weight: 100lbs Strength: 10, Endurance: 20, Agility: 20
                    player = Player(entityName, "Human", 100, 10, 20, 20)

                    # open up class types file and search for player's class
                    with open("entity_data/class_types.csv",
                              "r") as classTypeFile:
                        classReader = csv.reader(classTypeFile, delimiter=',')

                        for row in classReader:
                            # if class type (row[0]) is equal to player's class type (name[1])
                            if row[0] == name[1]:
                                player.classType = row[0]
                                # add items to players inventory
                                for item in row:
                                    if item != name[1] and itemCheck(
                                            item, "ITEMFOUND"):
                                        player.addItem(item)

                    # find item and apply it's stats to player
                    for item in range(player.inventorySize()):
                        print("Item: {}".format(player.getItem(item)))

                        # make sure item stored in inventory still exists
                        if itemCheck(player.getItem(item),
                                     "ITEMFOUND") == False:
                            return False

                        itemDirectory = itemCheck(player.getItem(item),
                                                  "ITEMLOCATION")

                        # open file where item is stored
                        with open(itemDirectory, "r") as itemFile:
                            itemReader = csv.reader(itemFile, delimiter=',')

                            # search for item name in the first string of every row
                            for row in itemReader:

                                if row[0] == player.getItem(item):
                                    # apply the rest of items stats that can be applied to player (weight, strength, endurance etc...)
                                    player.applyStats(row[3], row[4], row[5],
                                                      row[6])
                                    break
                            break

                    # return initialized player
                    return player

                elif entityType == "enemy":
                    with open("entity_data/enemy.csv") as file:
                        reader = csv.reader(file, delimiter=',')

                        for row in reader:
                            if row[0] == entityName:
                                # intialize an enemy with values found in row
                                enemy = Enemy(entityName, row[1], row[2])

                    # return initialized enemy
                    return enemy

                else:
                    print("Entity type does not exist.")
    return False
Пример #9
0
    def place_entities(self, room, entities, max_monsters_per_room,
                       max_items_per_room):
        """
        Cette méthode crée et place les différentes entités autres que le joueur sur la carte.

        """

        # on génère un nombre aléatoire de monstres et d'items
        number_of_monsters = randint(0, max_monsters_per_room)
        number_of_items = randint(0, max_items_per_room)

        for i in range(number_of_monsters):
            # On choisi une position aléatoire dans la chambre
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            # on verifie que cette position est libre
            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                # any(...) retourne False si la liste est vide (ce qui voudra dire
                # que la position (x,y) est libre) et True sinon
                monster_chance = randint(0, 100)

                if monster_chance < 10:
                    # il ya 80% de chance que ce soit un AssassinCat
                    fighter_component = Fighter(hp=15, defense=2, power=5)
                    ai_component = BasicMonster()

                    monster = Monster(x,
                                      y,
                                      'A',
                                      libtcod.magenta,
                                      'AssassinCat',
                                      render_order=RenderOrder.ACTOR,
                                      blocks=True,
                                      fighter=fighter_component,
                                      ai=ai_component)
                elif monster_chance < 40:
                    # 20% de chance que ce soit un Bat
                    fighter_component = Fighter(hp=10, defense=1, power=4)
                    ai_component = BasicMonster()

                    monster = Monster(x,
                                      y,
                                      'B',
                                      libtcod.azure,
                                      'Bat',
                                      render_order=RenderOrder.ACTOR,
                                      blocks=True,
                                      fighter=fighter_component,
                                      ai=ai_component)
                elif monster_chance < 80:
                    # 20% de chance que ce soit un Hobgoblin
                    fighter_component = Fighter(hp=10, defense=0, power=3)
                    ai_component = BasicMonster()

                    monster = Monster(x,
                                      y,
                                      'H',
                                      libtcod.grey,
                                      'Hobgoblin',
                                      render_order=RenderOrder.ACTOR,
                                      blocks=True,
                                      fighter=fighter_component,
                                      ai=ai_component)
                else:
                    # 20% de chance que ce soit un Troll
                    fighter_component = Fighter(hp=10, defense=1, power=4)
                    ai_component = BasicMonster()

                    monster = Monster(x,
                                      y,
                                      'T',
                                      libtcod.grey,
                                      'Troll',
                                      render_order=RenderOrder.ACTOR,
                                      blocks=True,
                                      fighter=fighter_component,
                                      ai=ai_component)

                entities.append(monster)

        for i in range(number_of_items):
            # On choisi une position aléatoire dans la chambre
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            # on verifie que cette position est libre
            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                item_chance = randint(0, 100)

                if item_chance < 60:
                    # il ya 60% de chance que ce soit une potion de guérison
                    item_component = comp.ItemComp(use_function=heal, amount=5)
                    item = Item(x,
                                y,
                                '!',
                                libtcod.violet,
                                'Potion',
                                render_order=RenderOrder.ITEM,
                                item=item_component)

                elif item_chance < 70:
                    # il ya 10% de chance que ce soit une boule de feu qui a le pouvoir
                    # d'exploser dans un rayon de 3
                    message = Message(
                        'Clique-gauche sur une tuile cible pour la boule de feu ou clique-droit pour annuler.',
                        libtcod.light_cyan)
                    item_component = comp.ItemComp(use_function=cast_fireball,
                                                   targeting=True,
                                                   targeting_message=message,
                                                   damage=12,
                                                   radius=4)
                    item = Item(x,
                                y,
                                '*',
                                libtcod.red,
                                'Boule de feu',
                                render_order=RenderOrder.ITEM,
                                item=item_component)

                elif item_chance < 90:
                    # il ya 20% de chance que ce soit un étourdisseur
                    message = Message(
                        "Clique-gauche sur une tuile cible pour le vertige ou clique-droit pour annuler.",
                        libtcod.light_cyan)
                    item_component = comp.ItemComp(use_function=cast_confuse,
                                                   targeting=True,
                                                   targeting_message=message)
                    item = Item(x,
                                y,
                                '§',
                                libtcod.light_pink,
                                'Vertige',
                                render_order=RenderOrder.ITEM,
                                item=item_component)

                else:
                    # il ya 10% de chance que ce soit la foudre
                    item_component = comp.ItemComp(use_function=cast_lightning,
                                                   damage=20,
                                                   maximum_range=5)
                    item = Item(x,
                                y,
                                '$',
                                libtcod.light_red,
                                'Foudre',
                                render_order=RenderOrder.ITEM,
                                item=item_component)

                entities.append(item)
Пример #10
0
orc = Actor(char="S",
            color=(63, 127, 63),
            name="Spoon",
            ai=HostileEnemy(),
            fighter=Fighter(hp=10, defense=0, power=3),
            inventory=Inventory(capacity=0))

troll = Actor(char="T",
              color=(0, 127, 0),
              name="Troll",
              ai=HostileEnemy(),
              fighter=Fighter(hp=16, defense=1, power=4),
              inventory=Inventory(capacity=0))

health_potion = Item(char="!",
                     color=(255, 255, 255),
                     name="HP Potion +4",
                     consumable=HealthPotion(amount=4))

health_potion_medium = Item(char="!",
                            color=(255, 255, 255),
                            name="HP Potion +10",
                            consumable=HealthPotion(amount=10))

health_potion_max = Item(char="!",
                         color=(255, 255, 255),
                         name="MAX HP Potion",
                         consumable=HealthPotion(amount=100))

ConsumableItems = [health_potion, health_potion_medium, health_potion_max]
Пример #11
0
)

grimm_reaper = Actor(
    char="R",
    color=(6, 0, 13),
    name="Da Grimm",
    ai_cls=HostileEnemy,
    equipment=Equipment(),
    fighter=Fighter(hp=30, base_defense=8, base_power=20),
    inventory=Inventory(capacity=0),
    level=Level(xp_given=200),
)

confusion_scroll = Item(
    char="~",
    color=(207, 63, 255),
    name="Confusion Scroll",
    consumable=consumable.ConfusionConsumable(number_of_turns=10),
)
fireball_scroll = Item(
    char="~",
    color=(255, 0, 0),
    name="Fireball Scroll",
    consumable=consumable.FireballDamageConsumable(damage=12, radius=3),
)

tornado_kitty = Item(
    char="&",
    color=(0, 106, 128),
    name="Tornado Kitty",
    consumable=consumable.TornadoKittyDamageConsumable(damage=11, radius=3),
)
Пример #12
0
    fighter=Fighter(hp=10, defense=0, power=3),
    inventory=Inventory(capacity=0),
)

troll = Actor(
    char="T",
    color=(0,127,0),
    name="Troll",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=16, defense=1, power=4),
    inventory=Inventory(capacity=0),
)

health_potion = Item(
    char="!",
    color=(127, 0, 255),
    name="Health Potion",
    consumable=consumable.HealingConsumable(amount=(lambda: (random.randint(1, 4)+2))),
)

lightning_scroll = Item(
    char="~",
    color=(255, 255, 0),
    name="Lightning Scroll",
    consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5),
)

confusion_scroll = Item(
    char="~",
    color=(207, 63, 255),
    name="Confusion Scroll",
    consumable=consumable.ConfusionConsumable(number_of_turns=10),
Пример #13
0
    color=(78, 81, 255),
    name="Jockster",
    ai_cls=HostileEnemy,
    equipment=Equipment(),
    fighter=Fighter(hp=18,
                    base_defense=2,
                    base_power=random.randint(5, 8),
                    max_hunger=1000,
                    hunger=1000),
    inventory=Inventory(capacity=0),
    level=Level(xp_given=125),
)

bandage = Item(
    char="#",
    color=(127, 0, 255),
    name="Bandage",
    consumable=consumable.HealingConsumable(amount=10),
)

burguer = Item(
    char="B",
    color=(255, 125, 0),
    name="Burguer",
    consumable=consumable.FoodConsumable(amount=10),
)

nugget = Item(char="N",
              color=(255, 125, 0),
              name="Chicken Nugget",
              consumable=consumable.FoodConsumable(amount=5))
Пример #14
0
    level=Level(xp_given=35),
)

troll = Actor(
    char='T',
    color=(0, 255, 255),
    name='Troll',
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=16, defense=1, power=4),
    inventory=Inventory(capacity=0),
    level=Level(xp_given=100),
)

health_potion = Item(
    char='!',
    color=(127, 0, 255),
    name="Harboe Sport",
    consumable=consumable.HealingConsumable(amount=4),
)

lightning_scroll = Item(
    char='~',
    color=(152, 60, 20),
    name="Scroll o'Lightning",
    consumable=consumable.LightningDamageConsumable(damage=20,
                                                    maximum_range=5),
)

confusion_scroll = Item(
    char='~',
    color=(207, 63, 255),
    name="Scroll o'Confusion",
Пример #15
0
from components.consumable import Consumable, HealingConsumable
from components.ai import BaseAI, Hostile
from components.fighter import Fighter
from components.inventory import Inventory
from entity import Actor, Item
from config import Config as CONFIG

player = Actor(name="Player",
               ai_cls=BaseAI,
               fighter=Fighter(hp=30, defense=2, power=5),
               inventory=Inventory(capacity=CONFIG.Game.get("inventory_size")))
# TODO Magic numbers!

blue = Actor(name="Blue",
             ai_cls=Hostile,
             fighter=Fighter(hp=10, defense=0, power=3),
             inventory=Inventory(0))
yellow = Actor(name="Yellow",
               ai_cls=Hostile,
               fighter=Fighter(hp=16, defense=1, power=4),
               inventory=Inventory(0))
health_potion = Item(
    name="Health Potion",
    consumable=HealingConsumable(amount=4),
)
Пример #16
0
def getName():
    return names.get_last_name()

def getUniquePerson():
    return Actor(
        char="T", 
        color=(63, 127, 0), 
        name=getName(),
        fighter=Fighter(energy=1), 
        ai_cls=OtherPerson
)

player = Actor(
    char="@", 
    color=colors.v_dark_purp, 
    name="Player", 
    fighter=Fighter(energy=100),
    ai_cls=OtherPerson,
    
)

food = Item(
    char="%",
    color=(127, 0, 255),
    name="Food",
    consumable=HealingConsumable(amount=7),
)

# me = Entity(char="o", color=(63, 127, 63), name="You", blocks_movement=True)

Пример #17
0
#########################################################################
################################ POTIONS ################################
#########################################################################

### Potion of healing
potion_of_healing = Item(
    char="!",
    fg=(127, 0, 255),
    name="Potion of healing",
    entity_id="potion_of_healing",
    entity_desc="Potion of healing desc",
    rarity=60,  #DEBUG
    weight=0.2,
    price=100,
    item_type=InventoryOrder.POTION,
    item_state=ItemState(),
    spawnable=True,
    flammable=0,
    droppable=True,
    stackable=True,
    throwable=throwable.NormalThrowable(break_chance=1),
    readable=None,
    quaffable=quaffable.PotionOfHealingQuaffable(amount=10),
)
item_lists.append(potion_of_healing)
item_rarity.append(potion_of_healing.rarity)
item_identified[
    potion_of_healing.entity_id] = potion_of_healing.item_state.is_identified

### Potion of paralysis
Пример #18
0
    char="o",
    color=(63, 127, 63),
    name="Orc",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=10, defense=0, power=3),
    inventory=Inventory(capacity=0),
)

troll = Actor(
    char="T",
    color=(0, 127, 0),
    name="Troll",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=16, defense=1, power=4),
    inventory=Inventory(capacity=0),
)

health_potion = Item(
    char="!",
    color=(127, 0, 255),
    name="Health Potion",
    consumable=consumable.HealingConsumable(amount=4),
)

lightning_scroll = Item(
    char="~",
    color=(255, 255, 0),
    name="Lightning Scroll",
    consumable=consumable.LightningDamageConsumable(damage=20,
                                                    maximum_range=5),
)
Пример #19
0
    level=Level(xp_given=100),
)

gunman = Actor(
    char="G",
    color=(0, 127, 0),
    name="Gunman",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=5, defense=0, power=1),
    inventory=Inventory(capacity=3),
    level=Level(xp_given=150),
)

confusion_scroll = Item(
    char="~",
    color=(207, 63, 255),
    name="Stack of Money",
    consumable=consumable.ConfusionConsumable(number_of_turns=10),
)

fireball_scroll = Item(
    char="~",
    color=(255, 0, 0),
    name="Molotov",
    consumable=consumable.FireballDamageConsumable(damage=12, radius=3),
)

health_potion = Item(
    char="!",
    color=(144, 75, 6),
    name="A Cold One",
    consumable=consumable.HealingConsumable(amount=4),
Пример #20
0
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=10, defense=0, power=3),
    inventory=Inventory(capacity=0),
)
monst2 = Actor(
    char="T",
    color=(142, 7, 54),
    name="Tiada",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=16, defense=1, power=4),
    inventory=Inventory(capacity=0),
)

first_aid = Item(
    char="+",
    color=(4, 161, 110),
    name="First Aid Kit",
    consumable=consumable.HealingConsumable(amount=6),
)

space_bomb = Item(
    char="*",
    color=(255, 255, 0),
    name="Space Bomb",
    consumable=consumable.BombDamageConsumable(damage=12, radius=3),
)

space_gun = Item(
    char="\"",
    color=(255, 255, 0),
    name="Space Gun",
    consumable=consumable.GunDamageConsumable(damage=20, maximum_range=5),
Пример #21
0
 def read_item(self, browser: selenium.webdriver.Chrome) -> (Item, None):
     """
     method:
         Rely the supplied jd item detail page. the method format read in info and then return a
         item instance.
     :param
         browser: an instance of browser which includes Chrome/Edge/FireFox etc.
         cautiously, the browser current page must be a commodity detail page.
     :return:
     """
     # TODO:有可能无货/链接无效
     if not self.is_jd_detail_page(browser):
         logging.info("[JdDetailPageReader.read_item]"
                      " Current page is't detail page:", browser.title)
         return None  # 判断是否是详情页
     item = Item()
     # 获取颜色标题及所选项目值
     color_dom = self.get_color_dom(browser)
     if color_dom is not None and len(color_dom) != 0:
         color_title_str = color_dom[0].text  # 获取标题
         color_selected_str = color_dom[1].find_element(By.CLASS_NAME, "selected").text  # 获取已选值
         item.spec1 = color_title_str + '=' + color_selected_str
     else:
         # 某些单一款不需要选颜色
         pass
     # 获取版本标题及所选项目值
     edition_dom = self.get_edition_dom(browser)
     if edition_dom is not None and len(edition_dom) != 0:
         edition_title_str = edition_dom[0].text
         edition_selected_str = edition_dom[1].find_element(By.CLASS_NAME, "selected").text
         item.spec2 = edition_title_str + '=' + edition_selected_str
     else:
         # 说明不需要选择型号,或者说没有型号信息
         pass
     # 获取商品url,可能因加载中等失败
     try:
         item.url = browser.current_url
     except TimeoutException:
         logging.warning('Get url failed! at method:JdDetailReader.read_item()')
         return None
     # 获取价格
     item.price = self.get_price(browser)
     if item.price == -1:
         logging.warning("JdDetailPageReader:Get price is -1\n" + item.url)
         return None
     # 获取plus会员价格
     item.plus_price = self.get_plus_price(browser)
     # 领券
     ticket_dom = self.get_ticket_dom(browser)
     if ticket_dom is not None and len(ticket_dom) != 0:
         ticket_str = ''
         for ti in ticket_dom:
             ticket_str += ti.text + '\n'
         item.ticket = ticket_str
     # 库存:京东不显示库存量,只有有无货之分
     # 快递费:京东各省价格均不同,有货情况也不同故不做记录
     # 销量
     item.sales_amount = self.get_remark(browser)
     # 可选字段
     # 生成所有字段
     item.generate_all_specification()
     return item
    fighter=Fighter(hp=10, defense=0, power=3),
    inventory=Inventory(capacity=0),
)

troll = Actor(
    char="T",
    color=(0, 127, 0),
    name="Troll",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=16, defense=1, power=4),
    inventory=Inventory(capacity=0),
)

confusion_scroll = Item(
    char="~",
    color=(207, 63, 255),
    name="Confusion Scroll",
    consumable=consumable.ConfusionConsumable(number_of_turns=10),
)

health_potion = Item(
    char="!",
    color=(127, 0, 255),
    name="Health Potion",
    consumable=consumable.HealingConsumable(amount=4),
)

lightning_scroll = Item(
    char="~",
    color=(255, 255, 0),
    name="Lightning Scroll",
    consumable=consumable.LightningDamageConsumable(damage=20,
Пример #23
0
    char="T",
    color=(0, 127, 0),
    name="Troll",
    ai_cls=HostileEnemy,
    equipment=Equipment(),
    fighter=Fighter(hp=16, base_defense=1, base_power=4),
    inventory=Inventory(capacity=0),
    level=Level(xp_given=100)
)

# scrolls
scroll_char = "?"

confusion_scroll = Item(
    char=scroll_char,
    color=(207, 63, 255),
    name="Confusion Scroll",
    consumable=consumable.ConfusionConsumable(number_of_turns=10)
)

magic_missile_scroll = Item(
    char=scroll_char,
    color=(85, 255, 85),
    name="Magic Missile Scroll",
    consumable=consumable.MagicMissileDamageConsumable(damage=16)
)

lightning_scroll = Item(
    char=scroll_char,
    color=(255, 255, 0),
    name="Lightning Scroll",
    consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5)
    inventory=Inventory(capacity=0),
    level=Level(xp_given=35),
)
troll = Actor(
    char="T",
    color=(0, 127, 0),
    name="Troll",
    ai_cls=HostileEnemy,
    equipment=Equipment(),
    fighter=Fighter(hp=16, base_defense=1, base_power=4),
    inventory=Inventory(capacity=0),
    level=Level(xp_given=100),
)
health_potion = Item(
    char="!",
    color=(127, 0, 255),
    name="Health Potion",
    consumable=consumable.HealingConsumable(amount=4),
)
lightning_scroll = Item(
    char="~",
    color=(255, 255, 0),
    name="Lightning Scroll",
    consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5),
)
confusion_scroll = Item(
    char="~",
    color=(207, 63, 255),
    name="Confusion Scroll",
    consumable=consumable.ConfusionConsumable(number_of_turns=10),
)
fireball_scroll = Item(
Пример #25
0
player = Actor(
    char="@",
    color=(255, 255, 255),
    name="Player",
    ai_cls=HostileEnemy,
    fighter=Fighter(hp=30, defense=1, power=7),
    inventory=Inventory(capacity=26),
    level=Level(level_up_base=200),
)

# small healing potions

open_front_unrounded_vowel = Item(
    char="Ω",
    color=(158, 48, 87),
    name="Open Front Unrounded Vowel",
    consumable=HealingConsumable(amount=4),
)

open_back_unrounded_vowel = Item(
    char="δ",
    color=(158, 48, 87),
    name="Open Back Unrounded Vowel",
    consumable=HealingConsumable(amount=5),
)

# medium healing potions

open_mid_front_unrounded_vowel = Item(
    char="∞",
    color=(158, 48, 87),