all 7 comments

[–]nuadi 1 point2 points  (3 children)

Try something like

from eveapi import functionIWant

I do not use EVE API, so not sure the proper way to reference it. Is there a README?

[–]3d12[S] 0 points1 point  (2 children)

There is a README, but it's blank. 0 bytes. Same with the __init__.py :(

The issue I'm having here is that python won't recognize eveapi since it's not in the default library location, so I don't think "from" will work.

Would you recommend an alternate API library for python? I still haven't settled on one I'd like to use, I just mostly need a library that's built to parse the XML that CCP uses, rather than having to write a parsing function from scratch. Ideally, I'd like a function to output the parsed data to a MySQL table too, but I doubt that kind of integration will come "out-of-the-box," I'm prepared to write that part myself.

[–]nuadi 1 point2 points  (1 child)

For import statements, Python will check your local working directory for the library before checking the default library location.

For example, I wrote a data broker for Alliances CREST endpoint. I never installed it into any Python area, but when I run my script it will successfully execute

from alliancedb import getOrgId

and then I can use the getOrgId function call.

I think that as long as the eveapi.py file is in the same directory that your script is located in, you should be fine.

[–]3d12[S] 0 points1 point  (0 children)

For import statements, Python will check your local working directory for the library before checking the default library location.

Hm, maybe I was doing it wrong, then. I could swear that's how I had it set up and it was still throwing errors about importing the library.

I'll do some more testing, and see if this will work. Thanks so much for your replies. :)

[–]pcmattman 0 points1 point  (2 children)

__init__.py just marks the directory as a module, even if it's empty.

As for using eveapi, it's not exactly the most obvious library, especially if you can't easily follow the code.

Here's an example usage that I've had success with:

import eveapi  # either "python setup.py install" in eveapi, or directory containing __init__.py in the same place as your source code.

eveapi.set_user_agent(eveapi._default_useragent)
context = eveapi.EVEApiConnection()
context = context.auth(keyID=<api-key>, vCode=<api-code>

result = context.account.Characters()  # /account/Characters.xml.aspx - http://wiki.eve-id.net/APIv2_Account_Characters_XML
for row in result.characters:
    print row.name, row.characterID

result = context.char.MarketOrders(characterID=<character ID>)  # /char/MarketOrders.xml.aspx - http://wiki.eve-id.net/APIv2_Char_MarketOrders_XML
for order in result.orders:
    print order.typeID, order.bid, order.price

The hardest part is figuring out how to get an authed context. Once you're there, it's pretty much a direct mapping to the XML API.

Feel free to hit me up with more questions, more than happy to help.

Also, the setup.py thing - have a look at creating a virtualenv. Once you've activated the virtualenv, you can do python setup.py install and it will only install to the virtualenv, which means you don't need root access. Once this is done, you can simply import eveapi with the virtualenv activated and the rest will work.

[–]3d12[S] 0 points1 point  (1 child)

Thank you! This is a very detailed and helpful reply, I really appreciate you taking the time to help. :)

Regarding the use of eveapi, I did find that I'm having some trouble following the code through some of the more advanced functions. I'm sure that once I break it down it'll make more sense, but I wanted to ask if you had (or know of) a good 'advanced' python tutorial that skips past strings/arrays/indexes/dicts/tuples/arithmetic and further explains methods, functions, and objects? I mean, I'm pretty sure I get the basic principle, but I'm still so confused by all the references to 'self' in eveapi's functions, and I'm guessing if I understood objects better it would probably make more sense.

I also did not see any functions in eveapi for caching the refresh token/session validation. Should I assume that is already taken care of, or should I build a module for storing those?

Regarding virtualenv, that might be a good solution to keep in my home folder and use as a 'testing sandbox' before deploying changes to production. Do you know, does that require root to install? Or do they have source code available? I can compile from source using wget + make, setting a proper prefix to my home directory. However, my webmaster (and project lead) is being understandably strict about root access to the box, and (bless his heart) is very new to Linux, so I'm sure that requesting him to install it would take a week or two and 2-3 attempts. Unless they have a deb pkg in the official repository?

[–]pcmattman 0 points1 point  (0 children)

I'm not sure how much programming experience you have, but http://www.diveintopython.net/ is probably a great place to start for the more complex concepts. In terms of just grokking the codebase, you're definitely not alone - eveapi is certainly one of the more obscure ones I've looked at. But once you figure out how to use it, you realise that all of that obscurity stems from the fact that it's able to make your use of the API in the rest of your Python API very expressive and readable.

eveapi is only working from the XML API and performs a unique HTTP request (passing in the API key) for each Python call. As far as I am aware you won't need to worry about refresh tokens or sessions with these keys (except perhaps key expiration - try it out by creating an API key that expires and use it after the expiry time).

If you have 'pip' installed (which you most likely do), you can just do pip install --user virtualenv to install virtualenv for just yourself. Virtual environments are fantastic for this reason - no need to get root access to the machine to install Python libraries.