-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExercice_04_xml.py
More file actions
50 lines (42 loc) · 1.23 KB
/
Exercice_04_xml.py
File metadata and controls
50 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
================================
Copyright (c) 2018, EPOS Project
================================
---
Three ways to call the FDSN-event's web service.
unid = '20170919_0000091'
"""
# -------------------------------------
# Main functions used in the EUrythmics
# -------------------------------------
# Func-Download
import requests
def geturl(url):
res = requests.get(url, timeout=15)
return {'status': res.status_code,
'content': res.text}
# Func-Parse (txt)
import csv
from io import StringIO
def parsecsv(txt, usedict=False):
if usedict:
parser = csv.DictReader(StringIO(txt), delimiter='|')
else:
parser = csv.reader(StringIO(txt), delimiter='|')
return [line for line in parser]
# Func-Parse (json)
import json
def parsejson(txt):
return json.loads(txt)
# Func-Parse (xml)
from obspy import read_events
def parsexml(url):
return read_events(url)
# ===================================
main_event = {'unid':'20170919_0000091'}
# Download and parse (xml)
url = "http://www.seismicportal.eu/fdsnws/event/1/query?eventid={unid}&format=xml".format(unid=main_event['unid'])
dataev = parsexml(url)
print("---parse-xml---\n{0}".format(dataev))