pyedxl - a python library for handling EDXL
I am proud to announce my latest work called pyedxl which is a python library for handling OASIS Emergency Data Exchange Language (EDXL) Distribution Element. At this time, it partially supports most of specification version 1.0 published on March 14, 2006. The main purpose to develop this library is to learn how to use lxml effectively. For those who can't stand to read, you might directly go to the Subversion repository.
Currently, there is not official release yet. I recommend all you to try the latest code in the repository. Below is the checkout command.
svn checkout http://pyedxl.googlecode.com/svn/trunk/ pyedxl
I also includes an example how to use it in
tests/ directory. Please don't
expect too much. There is only one example by now. In summary, the example is
gdacs.py that will convert fetched data from GDACS in RSS format
to EDXL and print out the latest entry.
You may specify an e-mail as a command line argument to indicate sender ID.
PYTHONPATH=. tests/gdacs.py email@example.com
In addition, you may specify the second argument as a local file or URL to override default RSS URL.
wget -O gdacs.xml http://www.gdacs.org/XML/RSS.xml PYTHONPATH=. tests/gdacs.py firstname.lastname@example.org gdacs.xml
See below for generated EDXL.
<EDXLDistribution xmlns="urn:oasis:names:tc:emergency:EDXL:DE:1.0"> <dateTimeSent>2006-12-16T14:20:34.308722</dateTimeSent> <senderID>email@example.com</senderID> <language>EN</language> <distributionType>Report</distributionType> <distributionStatus>Actual</distributionStatus> <combinedConfidentiality>UNCLASSIFIED AND NOT SENSITIVE</combinedConfidentiality> <distributionID>asgard:476</distributionID> <targetArea> <circle>1.220000,-77.170000,0.000000</circle> </targetArea> <contentObject> <embeddedXMLContent> <item xmlns="http://backend.userland.com/rss2" xmlns:gdas="http://www.gdacs.org" xmlns:asgard="http://asgard.jrc.it" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:geo="http://www.w3.org/2003/01/geo/" xmlns:glide="http://glidenumber.net"> <title>Orange volcano alert: Galeras (Colombia) is Erupting</title> <description>On Thursday, December 14, 2006, an activity change occurred in the volcano Galeras in Colombia. The volcano is Erupting with SWVRC alert level 3. Since this volcano is located in a region in which live about 1.5 million people in a 100 km area, the GDACS alert level is Orange.</description> <link>http://www.gdacs.org/reports.asp?eventType=VO&system=asgard&ID=476&alertlevel=Orange&location=CO&glide_no=VO-2005-000193-COL</link> <linkGeneric>http://www.gdacs.org/ArchiveFolder/archiveVO.asp?eventType=VO&color=Orange&status=Erupting&search=Search+events</linkGeneric> <pubDate>Thu, 14 Dec 2006 13:24 GMT+1</pubDate> <gdas:eventType>VO</gdas:eventType> <asgard:alertLevel>Alert Level 3</asgard:alertLevel> <gdas:alertLevel>Orange</gdas:alertLevel> <dc:subject>VO_Orange</dc:subject> <dc:subject>Erupting</dc:subject> <asgard:ID>476</asgard:ID> <asgard:date>Thu, 14 Dec 2006 13:24 GMT+1</asgard:date> <asgard:runDate>Thu, 14 Dec 2006 13:24 GMT+1</asgard:runDate> <VolcanoName>Galeras</VolcanoName> <VolcanoStatus>Erupting</VolcanoStatus> <VolcanoEventID>956</VolcanoEventID> <alertlevel>3</alertlevel> <geo:long>-77.17</geo:long> <geo:lat>1.22</geo:lat> <asgard:population>1587394</asgard:population> <gdas:country>Colombia</gdas:country> <glide:number id="" iso3="COL" year="" type="VO" number="000193">VO-2005-000193-COL</glide:number> </item> </embeddedXMLContent> </contentObject> </EDXLDistribution>
Hopefully this work is useful for anyone who want to develop softwares related to EDXL and its friend. In fact, Python has many XML implementation and lxml is one of them. They are able to parse any XML and generate them back to string again. However, it is not easy to know which elements must be added where in the XML tree.
Note that this is just a result of learning lxml, please don't expect performance and scalability from the current code.