Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml.etree.ElementTree in python

Status
Not open for further replies.

dheeraj2020

Programmer
Jan 13, 2015
1
0
0
IN
Hi,
i am new to xml parsing in python ,i used element tree and able to fetch data but mine is music player project that plays using the xml sheet

sample XML :

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428467</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:00:00</Airtime>
<Title>TRACK 29</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428467.aac</FileName>
<Duration>00:02:06</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428487</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:02:07</Airtime>
<Title>TRACK 57</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428487.aac</FileName>
<Duration>00:01:44</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428447</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:03:52</Airtime>
<Title>TRACK 06</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428447.aac</FileName>
<Duration>00:07:27</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428454</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:11:20</Airtime>
<Title>TRACK 14</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428454.aac</FileName>
<Duration>00:02:10</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428453</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:13:31</Airtime>
<Title>TRACK 13</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428453.aac</FileName>
<Duration>00:02:52</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428458</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:16:24</Airtime>
<Title>TRACK 20</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428458.aac</FileName>
<Duration>00:02:11</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428445</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:18:36</Airtime>
<Title>TRACK 04</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428445.aac</FileName>
<Duration>00:05:14</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
</newDataSet>

from this xml sheet the current system time has to be compared with the AIRTIME ,if it matches then grab the FILENAME and move to the particular folder where the file has saved and play...

i am able to get the Airtime and compare with system time like this:


>>> import xml.etree.ElementTree as ET
>>> import datetime
>>> now = datetime.datetime.now()
>>> td = now.strftime("%d-%m-%Y")
>>> tm = now.strftime("%H:%M:%S")
>>> path = 'C:/Users/dheedesk/Desktop/'
>>> newp = ''.join([path,td,'.xml'])
>>> tree = ET.parse(newp)
>>> root = tree.getroot()
for Airtime in root.iter("Airtime"):
if tm < Airtime:
print ""
elif tm == Airtime:
print ""
elif tm > Airtime:
print ""
else:
print ""

by this code i am getting the entire xml data,but i need only one time which is '<' or '=' to the current time and from that particular dataset it should grab the file name...
please.. help me on this, thank you.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top