-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_dmrpp.py
executable file
·46 lines (32 loc) · 1.51 KB
/
get_dmrpp.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
#!/usr/bin/env python3
"""
Given a URL to a file, nominally in S3 and managed by the EDC, get the paired DMR++ document.
This is not a replacement for the get_dmrpp command we bundle with Hyrax - it literally gets
a DMR++ document using HTTP. The command builds a DMR++ for a data file.
This file is part of the code used to build DMR++ invariant documents from the cache invalidation
objective of ESDIS NGAP PI 22.4.
"""
import requests
import time
def main():
import argparse
parser = argparse.ArgumentParser(description="Query CMR and get information about Collections and Granules, "
"especially as that information relates to OPeNDAP. EDC credentials "
"stored in ~/.netrc are needed. See the requests package for details.")
parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true")
parser.add_argument("-t", "--time", help="time responses from CMR", action="store_true")
parser.add_argument("url", help="The URL to a file that has a paired DMR++ document")
args = parser.parse_args()
try:
start = time.time()
r = requests.get(f'{args.url}.dmrpp')
duration = time.time() - start
if r.status_code == 200:
print(r.text)
else:
print(f'Error: {r.text}')
print(f'Request time: {duration:.1f}s') if args.time else ''
except Exception as e:
print(e)
if __name__ == "__main__":
main()