Exemple #1
0
class Gw2Itemstat(Base):
    """Map the itemstats endpoint

    This class gives access to v2/itemstats enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/itemstats
        - https://github.com/arenanet/api-cdi/blob/master/v2/itemstats.js

    This endpoint shows information about items stats
    """
    __tablename__ = "gw2_item_item_stat"
    __table_args__ = endpoint_def('itemstats', locale=True, workers=3)

    # Columns
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)

    agony_resistance = Column(
        Float,
        nullable=False,
        default=0,
        info=col_json(keys=['attributes', 'AgonyResistance']))
    boon_duration = Column(Float,
                           nullable=False,
                           default=0,
                           info=col_json(keys=['attributes', 'BoonDuration']))
    condition_damage = Column(
        Float,
        nullable=False,
        default=0,
        info=col_json(keys=['attributes', 'ConditionDamage']))
    condition_duration = Column(
        Float,
        nullable=False,
        default=0,
        info=col_json(keys=['attributes', 'ConditionDuration']))
    crit_damage = Column(Float,
                         nullable=False,
                         default=0,
                         info=col_json(keys=['attributes', 'CritDamage']))
    healing = Column(Float,
                     nullable=False,
                     default=0,
                     info=col_json(keys=['attributes', 'Healing']))
    power = Column(Float,
                   nullable=False,
                   default=0,
                   info=col_json(keys=['attributes', 'Power']))
    precision = Column(Float,
                       nullable=False,
                       default=0,
                       info=col_json(keys=['attributes', 'Precision']))
    thoughness = Column(Float,
                        nullable=False,
                        default=0,
                        info=col_json(keys=['attributes', 'Thoughness']))
    vitality = Column(Float,
                      nullable=False,
                      default=0,
                      info=col_json(keys=['attributes', 'Vitality']))
Exemple #2
0
class _Gw2DyeDetail(Base):
    """Store details about dye for each armor classes"""
    __tablename__ = "gw2_item_dye_detail"

    # Columns
    id = Column(Integer, ForeignKey("gw2_item_dye.id"), primary_key=True)
    type = Column(String, primary_key=True)

    brightness = Column(Integer, nullable=False)
    contrast = Column(Float, nullable=False)
    hue = Column(Integer, nullable=False)
    saturation = Column(Float, nullable=False)
    lightness = Column(Float, nullable=False)

    red = Column(Integer,
                 nullable=False,
                 info=col_json(keys='rgb', fn=lambda j, pj: j[0]),
                 default=0)
    green = Column(Integer,
                   nullable=False,
                   info=col_json(keys='rgb', fn=lambda j, pj: j[1]),
                   default=0)
    blue = Column(Integer,
                  nullable=False,
                  info=col_json(keys='rgb', fn=lambda j, pj: j[2]),
                  default=0)
Exemple #3
0
class _Gw2CharacterSpecialization(Base):
    """Store the character's currently selected specializations"""
    __tablename__ = "gw2_auth_character_spec"

    id = Column(Integer,
                ForeignKey("gw2_pro_specialization.id"),
                primary_key=True)
    type = Column(String, primary_key=True)
    char_id = Column(String,
                     ForeignKey("gw2_auth_character.name"),
                     primary_key=True)
    trait0_id = Column(Integer,
                       ForeignKey("gw2_pro_trait.id"),
                       nullable=True,
                       info=col_json(keys='traits',
                                     fn=lambda j, pj: j[0]
                                     if len(j) > 0 else None))
    trait1_id = Column(Integer,
                       ForeignKey("gw2_pro_trait.id"),
                       nullable=True,
                       info=col_json(keys='traits',
                                     fn=lambda j, pj: j[1]
                                     if len(j) > 1 else None))
    trait2_id = Column(Integer,
                       ForeignKey("gw2_pro_trait.id"),
                       nullable=True,
                       info=col_json(keys='traits',
                                     fn=lambda j, pj: j[2]
                                     if len(j) > 2 else None))

    specialization = relationship("Gw2Specialization", uselist=False)

    trait0 = relationship("Gw2Trait", foreign_keys=[trait0_id], uselist=False)
    trait1 = relationship("Gw2Trait", foreign_keys=[trait1_id], uselist=False)
    trait2 = relationship("Gw2Trait", foreign_keys=[trait2_id], uselist=False)
Exemple #4
0
class Gw2Skin(Base):
    """Map the skins endpoint

    This class gives access to v2/skins enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/skins
        - https://github.com/arenanet/api-cdi/blob/master/v2/skins.js

    This endpoint shows information about skins
    """
    __tablename__ = "gw2_item_skin"
    __table_args__ = endpoint_def('skins', locale=True)

    # Columns
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    type = Column(String, nullable=False)
    flags = Column(String, nullable=True)
    restrictions = Column(String, nullable=True)
    icon = Column(String, nullable=True)
    rarity = Column(String, nullable=False)
    description = Column(String, nullable=True)
    slot = Column(String, nullable=True, info=col_json(keys=['details', 'type']))
    weight_class = Column(String, nullable=True, info=col_json(keys=['details', 'weight_class']))
    damage_type = Column(String, nullable=True, info=col_json(keys=['details', 'damage_type']))
Exemple #5
0
class Gw2BackstoryAnswer(Base):
    """Map the backstory/answers endpoint

    This module gives access to v2/backstory/answers enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/backstory/answers
        - https://github.com/arenanet/api-cdi/blob/master/v2/backstory/answers.js

    This endpoint shows information about backstory answers
    """
    __tablename__ = "gw2_sto_backstory_answer"
    __table_args__ = endpoint_def('backstory/answers', locale=True, workers=1)

    # Columns
    pkid = Column(Integer, primary_key=True)
    id = Column(String, unique=True, nullable=False)
    title = Column(String, nullable=False)
    journal = Column(String, nullable=False)
    description = Column(String, nullable=False)
    question_id = Column(Integer,
                         ForeignKey("gw2_sto_backstory_question.id"),
                         nullable=False,
                         info=col_json(keys='question'))
    races = Column(String, nullable=True)
    professions = Column(String, nullable=True)

    # Relations
    question = relationship("Gw2BackstoryQuestion", uselist=False)
Exemple #6
0
class _Gw2CharacterSkill(Base):
    """Store the character's currently selected skills"""
    __tablename__ = "gw2_auth_character_skill"

    char_id = Column(Integer,
                     ForeignKey("gw2_auth_character.name"),
                     primary_key=True)
    type = Column(String, primary_key=True)
    heal_id = Column(Integer,
                     ForeignKey("gw2_pro_skill.id"),
                     nullable=True,
                     info=col_json(keys='heal'))
    util0_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=True,
                      info=col_json(keys='utilities',
                                    fn=lambda j, pj: j[0]
                                    if len(j) > 0 else None))
    util1_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=True,
                      info=col_json(keys='utilities',
                                    fn=lambda j, pj: j[1]
                                    if len(j) > 1 else None))
    util2_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=True,
                      info=col_json(keys='utilities',
                                    fn=lambda j, pj: j[2]
                                    if len(j) > 2 else None))
    elite_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=True,
                      info=col_json(keys='elite'))

    heal = relationship("Gw2Skill", foreign_keys=[heal_id], uselist=False)
    util0 = relationship("Gw2Skill", foreign_keys=[util0_id], uselist=False)
    util1 = relationship("Gw2Skill", foreign_keys=[util1_id], uselist=False)
    util2 = relationship("Gw2Skill", foreign_keys=[util2_id], uselist=False)
    elite = relationship("Gw2Skill", foreign_keys=[elite_id], uselist=False)
Exemple #7
0
class _Gw2FactPrefixedBuff(Gw2Fact):
    __tablename__ = "gw2_pro_fact_pbuff"

    skill_id = Column(Integer, ForeignKey("gw2_pro_fact.skill_id"), primary_key=True, default=0)
    trait_id = Column(Integer, ForeignKey("gw2_pro_fact.trait_id"), primary_key=True, default=0)
    ord = Column(Integer, ForeignKey("gw2_pro_fact.ord"), primary_key=True)
    is_traited = Column(Boolean, ForeignKey("gw2_pro_fact.is_traited"), primary_key=True)
    status = Column(String, nullable=True)
    description = Column(String, nullable=True)
    apply_count = Column(Integer, nullable=True)
    duration = Column(Integer, nullable=True)
    pre_text = Column(String, nullable=True, info=col_json(keys=['prefix', 'text']))
    pre_icon = Column(String, nullable=True, info=col_json(keys=['prefix', 'icon']))
    pre_status = Column(String, nullable=True, info=col_json(keys=['prefix', 'status']))
    pre_descr = Column(String, nullable=True, info=col_json(keys=['prefix', 'description']))

    __mapper_args__ = dict(
        polymorphic_identity='PrefixedBuff',
        inherit_condition=(skill_id == Gw2Fact.skill_id and
                           trait_id == Gw2Fact.trait_id and
                           ord == Gw2Fact.ord and
                           is_traited == Gw2Fact.is_traited)
    )
Exemple #8
0
class _Gw2ARTitle(_Gw2AchievementReward):
    __tablename__ = "gw2_misc_achievement_reward_title"
    __mapper_args__ = {'polymorphic_identity': 'Title'}

    # Columns
    pkid = Column(Integer,
                  ForeignKey("gw2_misc_achievement_reward.pkid"),
                  primary_key=True)
    title_id = Column(Integer,
                      ForeignKey("gw2_misc_title.id"),
                      nullable=False,
                      info=col_json(keys='id'))

    # Relations
    title = relationship("Gw2Title", uselist=False)
Exemple #9
0
class _Gw2ABMinipet(_Gw2AchievementBit):
    __tablename__ = "gw2_misc_achievement_bit_minipet"
    __mapper_args__ = {'polymorphic_identity': 'Minipet'}

    # Columns
    pkid = Column(Integer,
                  ForeignKey("gw2_misc_achievement_bit.pkid"),
                  primary_key=True)
    minipet_id = Column(Integer,
                        ForeignKey("gw2_item_minipet.id"),
                        nullable=False,
                        info=col_json(keys='id'))

    # Relations
    minipet = relationship("Gw2MiniPet", uselist=False)
Exemple #10
0
class _Gw2ABSkin(_Gw2AchievementBit):
    __tablename__ = "gw2_misc_achievement_bit_skin"
    __mapper_args__ = {'polymorphic_identity': 'Skin'}

    # Columns
    pkid = Column(Integer,
                  ForeignKey("gw2_misc_achievement_bit.pkid"),
                  primary_key=True)
    skin_id = Column(Integer,
                     ForeignKey("gw2_item_skin.id"),
                     nullable=False,
                     info=col_json(keys='id'))

    # Relations
    skin = relationship("Gw2Skin", uselist=False)
Exemple #11
0
class _Gw2ARItem(_Gw2AchievementReward):
    __tablename__ = "gw2_misc_achievement_reward_item"
    __mapper_args__ = {'polymorphic_identity': 'Item'}

    # Columns
    pkid = Column(Integer,
                  ForeignKey("gw2_misc_achievement_reward.pkid"),
                  primary_key=True)
    item_id = Column(Integer,
                     ForeignKey("gw2_item_item.id"),
                     nullable=False,
                     info=col_json(keys='id'))
    count = Column(Integer, nullable=False)

    # Relations
    item = relationship("Gw2Item", uselist=False)
Exemple #12
0
class _Gw2ARMastery(_Gw2AchievementReward):
    __tablename__ = "gw2_misc_achievement_reward_mastery"
    __mapper_args__ = {'polymorphic_identity': 'Mastery'}

    # Columns
    pkid = Column(Integer,
                  ForeignKey("gw2_misc_achievement_reward.pkid"),
                  primary_key=True)
    mastery_id = Column(Integer,
                        ForeignKey("gw2_pro_mastery.id"),
                        nullable=False,
                        info=col_json(keys='id'))
    region = Column(String, nullable=False)

    # Relations
    mastery = relationship("Gw2Mastery", uselist=False)
Exemple #13
0
class _Gw2CharacterEquipment(Base):
    """Store the character's current equipment"""
    __tablename__ = "gw2_auth_character_equipment"

    pkid = Column(Integer, primary_key=True)
    char_id = Column(Integer,
                     ForeignKey("gw2_auth_character.name"),
                     nullable=False)
    slot = Column(String, nullable=False)
    id = Column(Integer, ForeignKey("gw2_item_item.id"), nullable=False)
    skin_id = Column(Integer,
                     ForeignKey("gw2_item_skin.id"),
                     nullable=True,
                     info=col_json(keys='skin'))
    binding = Column(String, nullable=True)
    bound_to = Column(String, nullable=True)
    charges = Column(Integer, nullable=True)

    item = relationship("Gw2Item", foreign_keys=[id], uselist=False)
    skin = relationship("Gw2Skin", uselist=False)

    infusions = relationship(
        "Gw2UpgradeItem",
        secondary="gw2_auth_character_equipment_item_infusion_rel",
        uselist=True,
        info=rel_json(_Gw2CharacterEquipmentInfusion,
                      fn=lambda j, pj:
                      [dict(eqp_id=pj['pkid'], infusion_id=x) for x in j]))

    upgrades = relationship(
        "Gw2UpgradeItem",
        secondary="gw2_auth_character_equipment_item_upgrade_rel",
        uselist=True,
        info=rel_json(
            _Gw2CharacterEquipmentUpgrade,
            fn=lambda j, pj: [dict(eqp_id=pj['id'], upgrade_id=x) for x in j]))

    stats = relationship(
        "_Gw2CharacterEquipmentStat",
        uselist=False,
        info=rel_json(_Gw2CharacterEquipmentStat,
                      fn=lambda j, pj: dict(eqp_id=pj['id'],
                                            id=j['id'],
                                            **(j['attributes']
                                               if 'attributes' in j else {
                                                   'aze': 'rty'
                                               }))))
Exemple #14
0
class _Gw2AccountBank(Base):
    """Map the account/bank endpoint

    This endpoint shows the stored items in the account bank
    """
    __tablename__ = "gw2_auth_account_bank"
    __table_args__ = endpoint_def('account/bank',
                                  ep_type=EPType.sac,
                                  workers=1,
                                  rights=['account', 'inventories'],
                                  parent='Gw2Token')

    pkid = Column(Integer, primary_key=True)
    id = Column(Integer, ForeignKey("gw2_item_item.id"), nullable=False)
    api_key = Column(String,
                     ForeignKey("gw2_auth_account.api_key"),
                     nullable=False)
    count = Column(Integer, nullable=False)
    skin_id = Column(Integer,
                     ForeignKey("gw2_item_skin.id"),
                     nullable=True,
                     info=col_json(fn='skin'))
    binding = Column(String)
    bound_to = Column(String)
    charges = Column(Integer)

    item = relationship("Gw2Item", uselist=False)
    skin = relationship("Gw2Skin", uselist=False)

    upgrades = relationship(
        "Gw2UpgradeItem",
        secondary="gw2_auth_account_bank_upgrade",
        uselist=True,
        info=rel_json(
            _Gw2AccountBankUpgrade,
            fn=lambda j, pj: [dict(id=pj['pkid'], upgrade_id=x) for x in j]))

    infusions = relationship(
        "Gw2UpgradeItem",
        secondary="gw2_auth_account_bank_infusion",
        uselist=True,
        info=rel_json(
            _Gw2AccountBankUpgrade,
            fn=lambda j, pj: [dict(id=pj['pkid'], infusion_id=x) for x in j]))
Exemple #15
0
class _Gw2CharacterEquipmentStat(Base):
    __tablename__ = "gw2_auth_character_equipment_stat"

    eqp_id = Column(Integer,
                    ForeignKey("gw2_auth_character_equipment.pkid"),
                    primary_key=True)
    id = Column(Integer, ForeignKey("gw2_item_item_stat.id"), nullable=False)
    power = Column(Integer,
                   nullable=False,
                   default=0,
                   info=col_json(keys='Power'))
    precision = Column(Integer,
                       nullable=False,
                       default=0,
                       info=col_json(keys='Precision'))
    toughness = Column(Integer,
                       nullable=False,
                       default=0,
                       info=col_json(keys='Toughness'))
    vitality = Column(Integer,
                      nullable=False,
                      default=0,
                      info=col_json(keys='Vitality'))
    condition_damage = Column(Integer,
                              nullable=False,
                              default=0,
                              info=col_json(keys='ConditionDamage'))
    condition_duration = Column(Integer,
                                nullable=False,
                                default=0,
                                info=col_json(keys='ConditionDuration'))
    healing = Column(Integer,
                     nullable=False,
                     default=0,
                     info=col_json(keys='Healing'))
    boon_duration = Column(Integer,
                           nullable=False,
                           default=0,
                           info=col_json(keys='BoonDuration'))
Exemple #16
0
class _Gw2ProfWeapon(Base):
    __tablename__ = "gw2_pro_profession_weapon"

    prof_id = Column(Integer,
                     ForeignKey("gw2_pro_profession.pkid"),
                     primary_key=True)
    name = Column(String, primary_key=True)
    spec_id = Column(Integer,
                     ForeignKey("gw2_pro_specialization.id"),
                     nullable=True,
                     info=col_json(fn='specialization'))

    specialization = relationship("Gw2Specialization", uselist=False)
    skills = relationship(
        "_Gw2ProfWeaponSkill",
        uselist=True,
        info=rel_json(
            _Gw2ProfWeaponSkill,
            fn=lambda j, pj:
            [dict(prof_id=pj['prof_id'], weapon=pj['name'], **x) for x in j]))
Exemple #17
0
class Gw2Legend(Base):
    """Map the Revenant's legends endpoint

    This class gives access to v2/legends enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/legends
        - https://github.com/arenanet/api-cdi/blob/master/v2/legends.js

    This endpoint shows information about legends
    """
    __tablename__ = "gw2_pro_legend"
    __table_args__ = endpoint_def('legends', workers=1)

    pkid = Column(Integer, primary_key=True)
    id = Column(String, unique=True, nullable=False)
    swap_id = Column(Integer,
                     ForeignKey("gw2_pro_skill.id"),
                     nullable=False,
                     info=col_json(keys='swap'))
    heal_id = Column(Integer,
                     ForeignKey("gw2_pro_skill.id"),
                     nullable=False,
                     info=col_json(keys='heal'))
    elite_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=False,
                      info=col_json(keys='elite'))
    util0_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=False,
                      info=col_json(keys='utilities', fn=lambda j, pj: j[0]))
    util1_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=False,
                      info=col_json(keys='utilities', fn=lambda j, pj: j[1]))
    util2_id = Column(Integer,
                      ForeignKey("gw2_pro_skill.id"),
                      nullable=False,
                      info=col_json(keys='utilities', fn=lambda j, pj: j[2]))

    swap = relationship("Gw2Skill", foreign_keys=[swap_id], uselist=False)
    heal = relationship("Gw2Skill", foreign_keys=[heal_id], uselist=False)
    elite = relationship("Gw2Skill", foreign_keys=[elite_id], uselist=False)
    util0 = relationship("Gw2Skill", foreign_keys=[util0_id], uselist=False)
    util1 = relationship("Gw2Skill", foreign_keys=[util1_id], uselist=False)
    util2 = relationship("Gw2Skill", foreign_keys=[util2_id], uselist=False)
Exemple #18
0
class Gw2Title(Base):
    """Map the titles endpoint

    This class gives access to v2/titles enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/titles
        - https://github.com/arenanet/api-cdi/blob/master/v2/titles.js

    This endpoint shows information about titles
    """
    __tablename__ = "gw2_misc_title"
    __table_args__ = endpoint_def('titles', locale=True, workers=1)

    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    ap_required = Column(Integer, nullable=True)
    achievement_id = Column(Integer, ForeignKey("gw2_misc_achievement.id"), nullable=True, info=col_json(keys='achievement'))

    achievement = relationship("Gw2Achievement", uselist=False)
Exemple #19
0
class Gw2Guild(Base):
    """Map the guild/:id endpoint

    This class gives access to v2/guild/:id enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/guild/:id
        - https://github.com/arenanet/api-cdi/blob/master/v2/guild/details.js

    This endpoint shows the informations of a guild
    """
    __tablename__ = "gw2_auth_guild"
    __table_args__ = endpoint_def('guild/%s',
                                  EPType.psac,
                                  workers=3,
                                  parent='Gw2Account')

    pkid = Column(Integer, primary_key=True)
    id = Column(String, primary_key=True)
    api_key = Column(String,
                     ForeignKey("gw2_auth_account.api_key"),
                     primary_key=True)
    name = Column(String, nullable=False)
    tag = Column(String, nullable=False)
    level = Column(Integer)
    motd = Column(String)
    influence = Column(Integer)
    aetherium = Column(Integer)
    favor = Column(Integer)
    emblem_bid = Column(Integer,
                        ForeignKey("gw2_misc_emblem_back_layer.emblem_id"),
                        nullable=False,
                        info=col_json(keys=['emblem', 'background', 'id']))
    emblem_fid = Column(Integer,
                        ForeignKey("gw2_misc_emblem_fore_layer.emblem_id"),
                        nullable=False,
                        info=col_json(keys=['emblem', 'foreground', 'id']))
    emblem_flags = Column(String,
                          nullable=False,
                          info=col_json(keys=['emblem', 'flags']))

    emblem_back = relationship("_Gw2EmblemBackgroundLayer", uselist=True)
    emblem_back_colors = relationship(
        "Gw2Dye",
        secondary="gw2_auth_guild_emblem_back_color",
        info=rel_json(_Gw2GuildEmblemBackColor,
                      keys=['emblem', 'background', 'colors'],
                      fn=lambda j, pj: [{
                          'color_id': x,
                          'order': i,
                          'guild_pkid': pj['pkid']
                      } for i, x in enumerate(j)]))
    emblem_fore = relationship("_Gw2EmblemForegroundLayer", uselist=True)
    emblem_fore_colors = relationship(
        "Gw2Dye",
        secondary="gw2_auth_guild_emblem_fore_color",
        info=rel_json(_Gw2GuildEmblemForeColor,
                      keys=['emblem', 'foreground', 'colors'],
                      fn=lambda j, pj: [{
                          'color_id': x,
                          'order': i,
                          'guild_pkid': pj['pkid']
                      } for i, x in enumerate(j)]))

    @staticmethod
    def from_parent(_pjson):
        ids = [(x, ) for x in _pjson['guild_leader']]
        ids.extend([(x, ) for x in _pjson['guilds']
                    if x not in _pjson['guild_leader']])
        return (ids, None)
Exemple #20
0
class Gw2Character(Base):
    """Map the characters endpoint

    This class gives access to v2/characters enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/characters
        - https://github.com/arenanet/api-cdi/blob/master/v2/characters/characters.js

    This endpoint shows the informations of a character
    """
    __tablename__ = "gw2_auth_character"
    __table_args__ = endpoint_def('characters',
                                  ep_type=EPType.ac,
                                  workers=3,
                                  rights=['characters'],
                                  parent='Gw2Token')

    id = Column(Integer, primary_key=True)
    name = Column(String, unique=True, nullable=False)
    api_key = Column(String,
                     ForeignKey("gw2_auth_token.api_key"),
                     nullable=False)
    race = Column(String, nullable=False)
    gender = Column(String, nullable=False)
    prof_id = Column(String,
                     ForeignKey("gw2_pro_profession.id"),
                     nullable=False,
                     info=col_json(keys='profession'))
    level = Column(Integer, nullable=False)
    # guild_id = Column(Integer, ForeignKey("gw2_auth_guild.id"), nullable=True)
    age = Column(Integer, nullable=False)
    created = Column(DateTime,
                     nullable=False,
                     info=col_json(keys='created', fn=gw2_to_orm_date))
    deaths = Column(Integer, nullable=False)
    title_id = Column(Integer,
                      ForeignKey("gw2_misc_title.id"),
                      nullable=True,
                      info=col_json(keys='title'))

    backstory = relationship(
        "Gw2BackstoryAnswer",
        secondary="gw2_auth_character_backstory",
        uselist=True,
        info=rel_json(
            _Gw2CharacterBackStory,
            fn=lambda j, pj: [dict(char_id=pj['name'], ans_id=x) for x in j]))
    crafting = relationship(
        "_Gw2CharacterCraft",
        uselist=True,
        info=rel_json(
            _Gw2CharacterCraft,
            fn=lambda j, pj: [dict(char_id=pj['name'], **x) for x in j]))
    equipment = relationship(
        "_Gw2CharacterEquipment",
        uselist=True,
        info=rel_json(
            _Gw2CharacterEquipment,
            fn=lambda j, pj:
            [dict(char_id=pj['name'], **x) for x in j if x is not None]))
    # guild = relationship("Gw2Guild", uselist=False)
    inventory = relationship("_Gw2CharacterInventory",
                             uselist=True,
                             info=rel_json(_Gw2CharacterInventory,
                                           keys='bags',
                                           fn=lambda j, pj: [
                                               dict(char_id=pj['name'], **inv)
                                               for bag in j if bag is not None
                                               for inv in bag['inventory']
                                               if inv is not None
                                           ]))
    profession = relationship("Gw2Profession", uselist=False)
    skills = relationship(
        "_Gw2CharacterSkill",
        uselist=True,
        info=rel_json(
            _Gw2CharacterSkill,
            fn=lambda j, pj:
            [dict(char_id=pj['name'], type=k, **v) for k, v in j.items()]))
    specializations = relationship(
        "_Gw2CharacterSpecialization",
        uselist=True,
        info=rel_json(_Gw2CharacterSpecialization,
                      fn=lambda j, pj: [
                          dict(char_id=pj['name'], type=k, **_v)
                          for k, v in j.items() for _v in v if _v is not None
                      ]))
    title = relationship("Gw2Title", uselist=False)
    training = relationship(
        "_Gw2CharacterTrain",
        uselist=True,
        info=rel_json(
            _Gw2CharacterTrain,
            fn=lambda j, pj: [dict(char_id=pj['name'], **x) for x in j]))
Exemple #21
0
class Gw2Dye(Base):
    """Map the colors endpoint

    This class gives access to v2/colors enpoint.
    For more informations about this endpoint, see:
        - https://wiki.guildwars2.com/wiki/API:2/colors
        - https://github.com/arenanet/api-cdi/blob/master/v2/colors.js

    This endpoint shows information about a dye
    """
    __tablename__ = "gw2_item_dye"
    __table_args__ = endpoint_def('colors', locale=True, workers=1)

    # Columns
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    item = Column(Integer, ForeignKey("gw2_item_item.id"), nullable=True)

    red = Column(Integer,
                 nullable=False,
                 info=col_json(keys='base_rgb', fn=lambda j, pj: j[0]),
                 default=0)
    green = Column(Integer,
                   nullable=False,
                   info=col_json(keys='base_rgb', fn=lambda j, pj: j[1]),
                   default=0)
    blue = Column(Integer,
                  nullable=False,
                  info=col_json(keys='base_rgb', fn=lambda j, pj: j[2]),
                  default=0)

    hue = Column(String,
                 info=col_json(keys='categories',
                               fn=lambda j, pj: _intersect(j, _dye_hue)),
                 nullable=True)
    material = Column(String,
                      info=col_json(keys='categories',
                                    fn=lambda j, pj: _intersect(j, _dye_mat)),
                      nullable=True)
    rarity = Column(String,
                    info=col_json(keys='categories',
                                  fn=lambda j, pj: _intersect(j, _dye_rar)),
                    nullable=True)

    # Relations
    cloth = relationship(
        "_Gw2DyeDetail",
        primaryjoin=
        "_Gw2DyeDetail.id == Gw2Dye.id and _Gw2DyeDetail.type == 'cloth'",
        uselist=False,
        info=rel_json(_Gw2DyeDetail,
                      fn=lambda j, pj: dict(id=pj['id'], type='cloth', **j)))

    leather = relationship(
        "_Gw2DyeDetail",
        primaryjoin=
        "_Gw2DyeDetail.id == Gw2Dye.id and _Gw2DyeDetail.type == 'leather'",
        uselist=False,
        info=rel_json(_Gw2DyeDetail,
                      fn=lambda j, pj: dict(id=pj['id'], type='leather', **j)))

    metal = relationship(
        "_Gw2DyeDetail",
        primaryjoin=
        "_Gw2DyeDetail.id == Gw2Dye.id and _Gw2DyeDetail.type == 'metal'",
        uselist=False,
        info=rel_json(_Gw2DyeDetail,
                      fn=lambda j, pj: dict(id=pj['id'], type='metal', **j)))
Exemple #22
0
class Gw2Account(Base):
    """Map the account endpoint

    This class gives access to v2/account enpoint and its subendpoints.
    For more informations about these endpoints, see:
        - https://wiki.guildwars2.com/wiki/API:2/account and account/*
        - https://github.com/arenanet/api-cdi/tree/master/v2/account

    This endpoint shows the general informations of an account
    """
    __tablename__ = "gw2_auth_account"
    __table_args__ = endpoint_def('account',
                                  ep_type=EPType.sac,
                                  workers=1,
                                  rights=['account'],
                                  parent='Gw2Token')

    id = Column(String, primary_key=True)
    name = Column(String, primary_key=True)
    api_key = Column(String,
                     ForeignKey("gw2_auth_token.api_key"),
                     unique=True,
                     nullable=False)
    age = Column(Integer, nullable=False)
    world_id = Column(Integer,
                      ForeignKey("gw2_misc_world.id"),
                      nullable=False,
                      info=col_json('world'))
    created = Column(DateTime,
                     nullable=False,
                     info=col_json(keys='created', fn=gw2_to_orm_date))
    access = Column(String, nullable=False)
    commander = Column(Boolean, nullable=False)
    fractal_level = Column(Integer, nullable=True)
    daily_ap = Column(Integer, nullable=True)
    monthly_ap = Column(Integer, nullable=True)
    wvw_rank = Column(Integer, nullable=True)

    achievements = relationship("_Gw2AccountAchievement", uselist=True)
    bank = relationship("_Gw2AccountBank", uselist=True)
    dyes = relationship("Gw2Dye",
                        secondary="gw2_auth_account_dye",
                        uselist=True)
    finisher = relationship("_Gw2AccountFinisher", uselist=True)
    guilds = relationship("Gw2Guild", uselist=True)
    inventory = relationship("_Gw2AccountInventory", uselist=True)
    masteries = relationship("_Gw2AccountMastery", uselist=True)
    mini_pets = relationship("Gw2MiniPet",
                             secondary="gw2_auth_account_mini",
                             uselist=True)
    outfits = relationship("Gw2Outfit",
                           secondary="gw2_auth_account_outfit",
                           uselist=True)
    recipes = relationship("Gw2Recipe",
                           secondary="gw2_auth_account_recipe",
                           uselist=True)
    skins = relationship("Gw2Skin",
                         secondary="gw2_auth_account_skin",
                         uselist=True)
    titles = relationship("Gw2Title",
                          secondary="gw2_auth_account_title",
                          uselist=True)
    vault = relationship("_Gw2AccountVault", uselist=True)

    @staticmethod
    def merge_json(_json, parent, params):
        _json['_token_'] = parent

    @staticmethod
    def to_child(ch, key, _json):
        if len(set(ch.rights).intersection(
                _json['_token_']['permissions'])) == len(ch.rights):
            ch.set_params(key, _json)