Changeset 6


Ignore:
Timestamp:
06/30/2008 10:24:51 AM (14 years ago)
Author:
marcus
Message:
  • removed byte order mark
  • some changes for older versions of lxml and libxml
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Tools/ScXML2evt/scxml2evt.py

    r5 r6  
    1 #! /usr/bin/env python 
     1#! /usr/bin/env python 
     2# -*- coding: UTF8 -*- 
    23 
    34""" 
     
    3940 
    4041    def __init__(self, src, trgt): 
    41         parser = etree.XMLParser(remove_blank_text=True) 
    4242        self.target = trgt 
     43 
     44        # older version don't support XMLParser 
     45        try: 
     46            parser = etree.XMLParser(remove_blank_text=True) 
     47        except AttributeError: 
     48            parser = None 
    4349 
    4450        try: 
     
    129135 
    130136        # get information by xpath usage 
    131         picks_raw = x.xpath(".//pick") 
    132         arrivals_raw = x.xpath(".//arrival") 
     137        picks_raw = x.xpath("/seiscomp/EventParameters/pick") 
     138        arrivals_raw = x.xpath("/seiscomp/EventParameters/origin/arrival") 
     139 
     140        # no picks found 
     141        if not len(picks_raw) or not len(arrivals_raw): 
     142            print "error: no pick or arrival information found" 
     143            print "error: maybe you have a very old version of libxml/libxslt" 
     144            sys.exit(4) 
    133145 
    134146        # event information 
    135147        self.event = { 
    136             "time": self.sctime2sh(x.xpath(".//origin/time/value")[0].text), 
    137             "latitude": x.xpath(".//origin/latitude/value")[0].text, 
    138             "longitude": x.xpath(".//origin/longitude/value")[0].text, 
    139             "depth": x.xpath(".//origin/depth/value")[0].text, 
    140             "magnitude": x.xpath(".//origin/networkMagnitude/magnitude/value")[0].text, 
    141             "magnitude_type": x.xpath(".//origin/networkMagnitude/type")[0].text 
     148            "time": self.sctime2sh(x.xpath("/seiscomp/EventParameters/origin/time/value")[0].text), 
     149            "latitude": x.xpath("/seiscomp/EventParameters/origin/latitude/value")[0].text, 
     150            "longitude": x.xpath("/seiscomp/EventParameters/origin/longitude/value")[0].text, 
     151            "depth": x.xpath("/seiscomp/EventParameters/origin/depth/value")[0].text, 
     152            "magnitude": x.xpath("/seiscomp/EventParameters/origin/networkMagnitude/magnitude/value")[0].text, 
     153            "magnitude_type": x.xpath("/seiscomp/EventParameters/origin/networkMagnitude/type")[0].text 
    142154        } 
    143155 
Note: See TracChangeset for help on using the changeset viewer.