GithubHelp home page GithubHelp logo

battlenet's Introduction

battlenet

Python Library for Blizzard's Community Platform API

Major features

  • Pythonic
  • Unicode normalization
  • Lazyloading and eagerloading
  • Support locales (en, fr, de, ...)

Making a connection

Global connection settings can be setup so that objects can make connections implicitly.

from battlenet import Connection

Connection.setup(public_key='your public key', private_key='your private key', locale='fr')

You can also create connections explicitly.

from battlenet import Connection

connection = Connection(public_key='your public key', private_key='your private key', locale='fr')

Fetching a specific realm

from battlenet import Realm

# If a global connection was setup
realm = Realm(battlenet.UNITED_STATES, 'Nazjatar')

# Using a specific connection
realm = connection.get_realm(battlenet.UNITED_STATES, 'Nazjatar')

print realm.name
# => Nazjatar

print realm.is_online()
# => true

print realm.type
# => PVP

Fetching all realms

for realm in connection.get_all_realms(battlenet.UNITED_STATES):
    print realm

Fetching a character

from battlenet import Character

# If a global connection was setup
character = Character(battlenet.UNITED_STATES, 'Nazjatar', 'Vishnevskiy', fields=[Character.GUILD])

# Using a specific connection
character = connection.get_character(battlenet.UNITED_STATES, 'Nazjatar', 'Vishnevskiy', fields=[Character.GUILD])

print character.name
# => Vishnevskiy

print character.guild.name
# => Excellence

Fetching a guild

from battlenet import Guild

# If a global connection was setup
guild = Guild(battlenet.UNITED_STATES, 'Nazjatar', 'Excellence')

# Using a specific connection
guild = connection.get_guild(battlenet.UNITED_STATES, 'Nazjatar', 'Excellence')

print guild.name
# => Excellence

leader = guild.get_leader()
print leader.name
# => Clí

More Examples

Read the unit tests inside the tests directory.

battlenet's People

Contributors

crote avatar ngerakines avatar paca-project avatar puckch avatar scragg0x avatar vishnevskiy avatar winks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

battlenet's Issues

Test failure in test_character.py: Mismatching achievement dates?

Test failure in test_character.py: Mismatching achievement dates?

File "test_character.py", line 104, in test_achievements
self.assertEqual(character.achievements[513], datetime.datetime(2011, 1, 25, 12, 22, 8))
AssertionError: datetime.datetime(2011, 1, 25, 15, 22, 8) != datetime.datetime(2011, 1, 25, 12, 22, 8)

Hello? What's the status of this?

The version of this project on PyPi is three years old. #23 was opened a year and a half ago to update it, and hasn't even been commented on. There are a bunch of open pull requests with little to no activity.

I need something like this for a project of mine, and more importantly, I need something that works with Python 3.

Is it worth it for me to open a pull request? @vishnevskiy, do you have interest in continuing development on this? If not, would you consider letting someone else take over the project here and on PyPi? If no to both, would you mind if I forked this, renamed it, merged some of these outstanding PRs, and uploaded that to pypi?

Changes needed in things.py to support Python 2.5

"namedtuple" is a Python 2.6 feature not present in 2.5. The Google App Engine environment requires Python 2.5.

File "test/battlenet/things.py", line 529, in init
Tree = collections.namedtuple('Tree', ('points', 'total',))
AttributeError: 'module' object has no attribute 'namedtuple'

If you could use something other than namedtuple that would be great! :)

PyPi

Do you have any plans to update the version of this library that's on PyPi? Or was it someone else that posted it there?

doesn't support russian names

If guildwork are using your lib atm then it doesn't support names in russian, i think it caused by link encoding.

Test fails for test_data.py, APIError: HTTP Error 500: Internal Server Error

A test in test_data.py fails with a 500 error.

File "test/test_data.py", line 70, in test_items
item = self.connection.get_item(battlenet.UNITED_STATES, 60249)
File "test/battlenet/connection.py", line 217, in get_item
data = self.make_request(region, '/data/item/%d' % item_id)
File "test/battlenet/connection.py", line 110, in make_request
raise APIError(str(e))
APIError: HTTP Error 500: Internal Server Error

very minor typo

in things.py, line 453

self.average_item_level_equiped = data['averageItemLevelEquipped']

should be

self.average_item_level_equipped = data['averageItemLevelEquipped']

(missing a 'p')

No mastery

If a talent tree is blank there is no name or icon

battle.net api issues

  • Enchants on equipped items should be Item Ids?
  • No information on how to relate criteria with achievements on guild API
  • Titles are invalid and no way to know the selected title in character API
  • Hunter pets do not have talents in character API
  • Faction on guild API is not consistent with character API's guild value
  • Emblem is not provided by guild API, but provided by character API's guild value
  • No recent activity feed

Text encoding issue?

Throws error when attempting to decode inputs of non-standard english characters. For instance, test_unicode () in test_character.py results in:

ERROR: test_unicode (main.CharacterTest)

Traceback (most recent call last):
File "C:\Users\Isaac\Desktop\test_character.py", line 87, in test_unicode
character = Character(battlenet.UNITED_STATES, 'Nazjatar', 'Clí')
File "D:\Python27\lib\battlenet\things.py", line 135, in init
data = self.connection.get_character(region, realm, name, raw=True, fields=self._fields)
File "D:\Python27\lib\battlenet\connection.py", line 114, in get_character
name = quote(name.lower())
File "D:\Python27\lib\battlenet\utils.py", line 13, in quote
return urllib.quote(normalize(name))
File "D:\Python27\lib\battlenet\utils.py", line 7, in normalize
name = name.decode('utf8')
File "D:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-3: unexpected end of data


I ran this test after the following resulted in a similar error:

import battlenet
from battlenet import Connection, Character
character = Character(battlenet.UNITED_STATES,'Stormreaver','Tøth',fields=[Character.ITEMS]) 

ø is character 248 in Latin1. Resulting error reads:

Traceback (most recent call last):
File "<pyshell#2>", line 1, in
character = Character(battlenet.UNITED_STATES,'Stormreaver','Tøth',fields=[Character.ITEMS])
File "D:\Python27\lib\battlenet\things.py", line 135, in init
data = self.connection.get_character(region, realm, name, raw=True, fields=self._fields)
File "D:\Python27\lib\battlenet\connection.py", line 114, in get_character
name = quote(name.lower())
File "D:\Python27\lib\battlenet\utils.py", line 13, in quote
return urllib.quote(normalize(name))
File "D:\Python27\lib\battlenet\utils.py", line 7, in normalize
name = name.decode('utf8')
File "D:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf8 in position 1: invalid start byte


Possible user error? I ran the test to be sure. Running Python 2.7 on Windows.

Automatic updating of characters fails with unicode names

As stated in the title, updating a character by referring to unknown data fails for names which require unicode characters

Code example:

import battlenet
REGION = battlenet.UNITED_STATES
REALM = 'Nazjatar'
GUILD = 'Excellence'

from battlenet import Connection
from battlenet import Guild
from battlenet import Character
Connection.setup()

def test_1():
    g = Guild(REGION, REALM, GUILD, fields=[Guild.MEMBERS])
    c = g.get_leader()
    foo = c.talents    # Produces an error

def test_2():
    c = Character(REGION, REALM, u'Clí')
    foo = c.talents    # Another error

def test_3():
    c = Character(REGION, REALM, u'Clí', fields=[Character.TALENTS])
    foo = c.talents    # Works fine

The error returned:

 Traceback (most recent call last):
  File "<<Work Directory>>\testsuite.py", line 17, in <module>
    foo = c.talents
  File "<<Work Directory>>\battlenet\things.py", line 254, in talents
    if self._refresh_if_not_present(Character.TALENTS):
  File "<<Work Directory>>\battlenet\things.py", line 43, in _refresh_if_not_present
    self.refresh(field)
  File "<<Work Directory>>\battlenet\things.py", line 271, in refresh
    self.name, raw=True, fields=self._fields))
  File "<<Work Directory>>\battlenet\connection.py", line 114, in get_character
    name = quote(name.lower())
  File "<<Work Directory>>\battlenet\utils.py", line 13, in quote
    return urllib.quote(normalize(name))
  File "<<Work Directory>>\battlenet\utils.py", line 7, in normalize
    name = name.decode('utf8')
  File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-3: unexpected end of data

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.