forked from istSOS/istsos3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curl.py
76 lines (60 loc) · 1.57 KB
/
curl.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
# Inspired by Ken Weiner
# https://goo.gl/GkVRlg
import sys
import subprocess
from decimal import Decimal
url = sys.argv[1]
if len(sys.argv) == 1:
print("Web address not given")
exit()
getCapabilities = (
'service=SOS&request=GetCapabilities&service=SOS'
'&version=2.0.0&AcceptVersions=2.0.0'
)
describeSensor = (
'service=SOS&request=DescribeSensor&service=SOS'
'&version=2.0.0&procedure=urn:ogc:def:procedure:x-istsos:1.0:LUGANO'
'&procedureDescriptionFormat=http://www.opengis.net/sensorML/1.0.1'
)
getObservation = (
'service=SOS&request=GetObservation&service=SOS'
'&version=2.0.0&procedure=T_TRE'
'&temporalFilter=om:phenomenonTime,2006-01-01T00:00:00Z/'
'2008-01-01T00:00:00Z'
)
def execute(url):
print("\nAddress: %s\n" % (url))
process = subprocess.Popen([
'curl',
'-s',
'-w',
(
'%{time_namelookup},%{time_pretransfer},'
'%{time_starttransfer},%{time_total}'
),
'-o',
'/dev/null',
"%s" % (url)
],
stdout=subprocess.PIPE
)
out, err = process.communicate()
data = [Decimal(x) for x in out.split(",")]
result = """Time (in sec):
--------------
DNS Lookup: %s
TCP Connection: %s
Generation: %s
Download: %s
=====================
Total: %s
""" % (
data[0],
data[1] - data[0],
data[2] - data[1],
data[3] - data[2],
data[3]
)
print(result)
execute("%s?%s" % (url, getObservation))