Support Forums

Full Version: Python script pulling data from XML file for Eve-Online data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm in Ubuntu using Conky. I also play EVE-Online [and if you do, "No, I do not want to join your corp"]. I have this set of Python scripts that pull data from XML files that get my character status and other info. The problem is that the whole thing doesn't work; Nothing is outputted to my Conky. Seeing as I am unfamiliar with Python, I thought I'd ask you guys for some support.

I know that I'm getting the info OK because I can open the XML files and see perfectly clear that it contains a bunch of stuff about my character.

So let me just give you an example of what I'm dealing with; The following script gets my character name from the XML file:
Code:
#!/usr/bin/python
from xml.dom.minidom import parse
from xml import xpath
import os

doc = parse("/home/me/eve/character.xml")

print doc.getElementsByTagName("name")[0].childNodes[0].nodeValue,

And the following is a portion of the XML file:
Code:
<eveapi version="2">
  <currentTime>2009-11-10 00:53:09</currentTime>
  <result>
    <characterID>57371xxxx</characterID>
    <name>[My Name]</name>
    <race>Gallente</race>
    <bloodLine>Gallente</bloodLine>
    <gender>Male</gender>
. . . .etc, etc, etc. . . .

So the "print" command in that python script doesn't work; Why not?
Okay, further development: I tried running the Python script by itself in a terminal [works OK with my Gmail python script I use in Conky], but the following is the output:

Code:
xxx@xxx:~$ python /home/me/eve/eve-name.py
Traceback (most recent call last):
  File "/home/me/eve/eve-name.py", line 3, in <module>
    from xml import xpath
  File "/usr/lib/python2.6/dist-packages/_xmlplus/xpath/__init__.py", line 105, in <module>
    import Context
  File "/usr/lib/python2.6/dist-packages/_xmlplus/xpath/Context.py", line 15, in <module>
    import CoreFunctions
  File "/usr/lib/python2.6/dist-packages/_xmlplus/xpath/CoreFunctions.py", line 20, in <module>
    from xml.xpath import Util, Conversions
  File "/usr/lib/python2.6/dist-packages/_xmlplus/xpath/Conversions.py", line 22, in <module>
    from xml.utils import boolean
ImportError: cannot import name boolean

Can anybody interpret those compile errors? This is from running that script that I first posted above.
Well, you guys were basically no help. Haha, no worries, though. I spent all night reading, plus trial-and-error [Note: I knew nothing about Python going into it], and eventually developed this little script:
Code:
#!/usr/bin/env python
import xml.etree.ElementTree as ET
tree = ET.parse("/home/me/eve/character.xml")

def traverse(node):
    for c in node.getchildren():
    if c.tag == "name": print c.text
        traverse(c)

root = tree.getroot()
traverse(root)

And modified the search tag for each script I was using.
So, another project down. Plus, check out my screenshot:
[Image: evescriptshot.jpg]

Sweet, right? Eh, probably not if you're not into Eve [most of you aren't]. And from here, there's actually a lot more I could do with it, such as listing my specific skills or skills I'm training on. I've discovered that XML is pretty freaking awesome!