hdpws 0.6.25__py3-none-any.whl → 0.6.26__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hdpws/__init__.py +1 -1
- hdpws/hdpws.py +54 -1
- hdpws/spasehtmlparser.py +129 -0
- {hdpws-0.6.25.dist-info → hdpws-0.6.26.dist-info}/METADATA +3 -2
- hdpws-0.6.26.dist-info/RECORD +12 -0
- {hdpws-0.6.25.dist-info → hdpws-0.6.26.dist-info}/WHEEL +1 -1
- hdpws-0.6.25.dist-info/RECORD +0 -11
- {hdpws-0.6.25.dist-info → hdpws-0.6.26.dist-info/licenses}/LICENSE +0 -0
- {hdpws-0.6.25.dist-info → hdpws-0.6.26.dist-info}/top_level.txt +0 -0
hdpws/__init__.py
CHANGED
hdpws/hdpws.py
CHANGED
|
@@ -47,6 +47,7 @@ from dateutil import parser
|
|
|
47
47
|
from hdpws import __version__, NAMESPACES as NS
|
|
48
48
|
from hdpws.dateinterval import DateInterval
|
|
49
49
|
from hdpws.resourcetype import ResourceType
|
|
50
|
+
from hdpws.spasehtmlparser import SpaseHtmlParser
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
#
|
|
@@ -594,7 +595,7 @@ class HdpWs:
|
|
|
594
595
|
resource_id: str,
|
|
595
596
|
**keywords: Union[
|
|
596
597
|
datetime]
|
|
597
|
-
) ->
|
|
598
|
+
) -> Dict:
|
|
598
599
|
"""
|
|
599
600
|
Gets the an HTML representation of the specified SPASE document
|
|
600
601
|
from HDP.
|
|
@@ -658,6 +659,58 @@ class HdpWs:
|
|
|
658
659
|
return result
|
|
659
660
|
|
|
660
661
|
|
|
662
|
+
def get_spase_json_ld(
|
|
663
|
+
self,
|
|
664
|
+
resource_id: str,
|
|
665
|
+
**keywords: Union[
|
|
666
|
+
datetime]
|
|
667
|
+
) -> Dict:
|
|
668
|
+
"""
|
|
669
|
+
Gets the an JSON-LD representation of the specified SPASE document
|
|
670
|
+
from HDP.
|
|
671
|
+
|
|
672
|
+
Parameters
|
|
673
|
+
----------
|
|
674
|
+
resource_id
|
|
675
|
+
SPASE ResourceID value of the document to get.
|
|
676
|
+
keywords
|
|
677
|
+
Optional keyword paramaters as follows:<br>
|
|
678
|
+
<b>if_modified_since</b> - conditional GET If-Modified-Since
|
|
679
|
+
datetime value.<br>
|
|
680
|
+
|
|
681
|
+
Returns
|
|
682
|
+
-------
|
|
683
|
+
Dict
|
|
684
|
+
Dictionary containing a 'Result' key whose value is the JSON-LD
|
|
685
|
+
representation of the specified SPASE document with the
|
|
686
|
+
addition of the following key/values:<br>
|
|
687
|
+
- HttpStatus: with the value of the HTTP status code.
|
|
688
|
+
Successful == 200.<br>
|
|
689
|
+
- Last-Modified: the value of the HTTP Last-Modified header
|
|
690
|
+
when available.<br>
|
|
691
|
+
When HttpStatus != 200:<br>
|
|
692
|
+
- HttpText: containing a string representation of the HTTP
|
|
693
|
+
entity body.<br>
|
|
694
|
+
When HttpText is a standard HDP WS error entity body the
|
|
695
|
+
following key/values (convenience to avoid parsing
|
|
696
|
+
HttpStatus):<br>
|
|
697
|
+
- ErrorMessage: value from HttpText.<br>
|
|
698
|
+
- ErrorDescription: value from HttpText.<br>
|
|
699
|
+
"""
|
|
700
|
+
|
|
701
|
+
response = self.get_spase_html(resource_id, **keywords)
|
|
702
|
+
|
|
703
|
+
if response['HttpStatus'] != 200:
|
|
704
|
+
return response
|
|
705
|
+
|
|
706
|
+
spase_html_parser = SpaseHtmlParser()
|
|
707
|
+
spase_html_parser.feed(response['Result'])
|
|
708
|
+
|
|
709
|
+
response['Result'] = spase_html_parser.get_json_ld()
|
|
710
|
+
|
|
711
|
+
return response
|
|
712
|
+
|
|
713
|
+
|
|
661
714
|
def get_spase_data(
|
|
662
715
|
self,
|
|
663
716
|
resource_types: List[ResourceType],
|
hdpws/spasehtmlparser.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# NOSA HEADER START
|
|
5
|
+
#
|
|
6
|
+
# The contents of this file are subject to the terms of the NASA Open
|
|
7
|
+
# Source Agreement (NOSA), Version 1.3 only (the "Agreement"). You may
|
|
8
|
+
# not use this file except in compliance with the Agreement.
|
|
9
|
+
#
|
|
10
|
+
# You can obtain a copy of the agreement at
|
|
11
|
+
# docs/NASA_Open_Source_Agreement_1.3.txt
|
|
12
|
+
# or
|
|
13
|
+
# https://cdaweb.gsfc.nasa.gov/WebServices/NASA_Open_Source_Agreement_1.3.txt.
|
|
14
|
+
#
|
|
15
|
+
# See the Agreement for the specific language governing permissions
|
|
16
|
+
# and limitations under the Agreement.
|
|
17
|
+
#
|
|
18
|
+
# When distributing Covered Code, include this NOSA HEADER in each
|
|
19
|
+
# file and include the Agreement file at
|
|
20
|
+
# docs/NASA_Open_Source_Agreement_1.3.txt. If applicable, add the
|
|
21
|
+
# following below this NOSA HEADER, with the fields enclosed by
|
|
22
|
+
# brackets "[]" replaced with your own identifying information:
|
|
23
|
+
# Portions Copyright [yyyy] [name of copyright owner]
|
|
24
|
+
#
|
|
25
|
+
# NOSA HEADER END
|
|
26
|
+
#
|
|
27
|
+
# Copyright (c) 2025 United States Government as represented by
|
|
28
|
+
# the National Aeronautics and Space Administration. No copyright is
|
|
29
|
+
# claimed in the United States under Title 17, U.S.Code. All Other
|
|
30
|
+
# Rights Reserved.
|
|
31
|
+
#
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
Module defining a class to represent a SPASE HTML parser. At present,
|
|
36
|
+
its main function is to extract the JSON-LD embedded in an HTML
|
|
37
|
+
representation of a SPASE XML document. Any other information should
|
|
38
|
+
be obtained from the original SPASE XML document.<br>
|
|
39
|
+
|
|
40
|
+
Copyright © 2025 United States Government as represented by the
|
|
41
|
+
National Aeronautics and Space Administration. No copyright is claimed in
|
|
42
|
+
the United States under Title 17, U.S.Code. All Other Rights Reserved.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
from html.parser import HTMLParser
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class SpaseHtmlParser(HTMLParser):
|
|
51
|
+
"""
|
|
52
|
+
A class representing a SPASE HTML parser.
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
----------
|
|
56
|
+
json_ld_element
|
|
57
|
+
Flag indicating that we have encountered the json-ld element.
|
|
58
|
+
The value is set back to false when we encounter the end tag.
|
|
59
|
+
json_ld
|
|
60
|
+
The json-ld "data" extracted from the json-ld element.
|
|
61
|
+
"""
|
|
62
|
+
def __init__(self):
|
|
63
|
+
|
|
64
|
+
super().__init__()
|
|
65
|
+
|
|
66
|
+
self._json_ld_element = False
|
|
67
|
+
self._json_ld = None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def handle_starttag(self, tag, attrs):
|
|
71
|
+
"""
|
|
72
|
+
This method is called to handle the start tag of an element.
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
----------
|
|
76
|
+
tag
|
|
77
|
+
The name of the tag encountered.
|
|
78
|
+
attrs
|
|
79
|
+
List of (name, value) pairs containing the attributes found
|
|
80
|
+
inside the tag’s <> brackets.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
if tag == 'script':
|
|
84
|
+
for attr in attrs:
|
|
85
|
+
if attr[0] == 'type' and attr[1] == 'application/ld+json':
|
|
86
|
+
self._json_ld_element = True
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def handle_endtag(self, tag):
|
|
90
|
+
"""
|
|
91
|
+
This method is called to handle the end tag of an element.
|
|
92
|
+
|
|
93
|
+
Parameters
|
|
94
|
+
----------
|
|
95
|
+
tag
|
|
96
|
+
The name of the tag encountered.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
self._json_ld_element = False
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def handle_data(self, data):
|
|
103
|
+
"""
|
|
104
|
+
This method is called to process arbitrary data (e.g. text nodes
|
|
105
|
+
and the content of <script>...</script> and
|
|
106
|
+
<style>...</style>).
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
data
|
|
111
|
+
The content of the element.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
if self._json_ld_element:
|
|
115
|
+
|
|
116
|
+
self._json_ld = data
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def get_json_ld(self) -> str:
|
|
120
|
+
"""
|
|
121
|
+
Gets the JSON-LD from the SPASE HTML fed to this parser.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
--------
|
|
125
|
+
str
|
|
126
|
+
JSON-LD from the SPASE HTML or None.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
return self._json_ld
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: hdpws
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.26
|
|
4
4
|
Summary: NASA's Heliophysics Data Portal Web Service Client Library
|
|
5
5
|
Home-page: https://heliophysicsdata.gsfc.nasa.gov/WebServices
|
|
6
6
|
Author: Bernie Harris
|
|
@@ -32,6 +32,7 @@ Dynamic: description-content-type
|
|
|
32
32
|
Dynamic: home-page
|
|
33
33
|
Dynamic: keywords
|
|
34
34
|
Dynamic: license
|
|
35
|
+
Dynamic: license-file
|
|
35
36
|
Dynamic: requires-dist
|
|
36
37
|
Dynamic: summary
|
|
37
38
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
hdpws/__init__.py,sha256=3LQbCNWobLUcELAXwKVjSfIBV9l6R_-p4cow0n6Duj4,2059
|
|
2
|
+
hdpws/__main__.py,sha256=RqdpMcxCUztmqE4YaZ7Gr-CQAkq4TLZyw1FYWqmxpJY,15294
|
|
3
|
+
hdpws/dateinterval.py,sha256=OwFRQUbTMyzR1R7T5gSKT2st4PbLWAwOtcsP7_PqQys,4901
|
|
4
|
+
hdpws/hdpws.py,sha256=0UE3pCFC0wwrHZXbAf67WuLG-BQTQ5xb-k83IrZHPvU,41973
|
|
5
|
+
hdpws/resourcetype.py,sha256=ybBKFKDcVesRkRKb-mEXIxRt-INed3QZzysx1rmy6bo,1771
|
|
6
|
+
hdpws/spase.py,sha256=ylnH9mh1McwwyB6-LzaOOWr1ggJiuNgcEH3-6mXJjfI,13343
|
|
7
|
+
hdpws/spasehtmlparser.py,sha256=1eSahtKAydGpoor3oTLS5cxxaFW8nvIrUcdHbnLmC-A,3612
|
|
8
|
+
hdpws-0.6.26.dist-info/licenses/LICENSE,sha256=9VDxMcDDn3_T-sDQTMPxmiPZBDkPIiTO4OzYK5olDmk,12589
|
|
9
|
+
hdpws-0.6.26.dist-info/METADATA,sha256=aUz9Tjzcy3UCrDlVMmu9lPiWl4Zz6HZJQNAssNQU-bk,3876
|
|
10
|
+
hdpws-0.6.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
hdpws-0.6.26.dist-info/top_level.txt,sha256=BTo-2sxU1YuKAD5Ykfc8bNQvgVX486A74voiQxV4NiQ,6
|
|
12
|
+
hdpws-0.6.26.dist-info/RECORD,,
|
hdpws-0.6.25.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
hdpws/__init__.py,sha256=XPpGzl_P1W82Iua96XJSwlDdHh7JgsxHGZzNRb0hvcw,2059
|
|
2
|
-
hdpws/__main__.py,sha256=RqdpMcxCUztmqE4YaZ7Gr-CQAkq4TLZyw1FYWqmxpJY,15294
|
|
3
|
-
hdpws/dateinterval.py,sha256=OwFRQUbTMyzR1R7T5gSKT2st4PbLWAwOtcsP7_PqQys,4901
|
|
4
|
-
hdpws/hdpws.py,sha256=EYnnCo2JtkP5GjpykxF6VGz1NmGFTVTuh3g4yjCAmqQ,40168
|
|
5
|
-
hdpws/resourcetype.py,sha256=ybBKFKDcVesRkRKb-mEXIxRt-INed3QZzysx1rmy6bo,1771
|
|
6
|
-
hdpws/spase.py,sha256=ylnH9mh1McwwyB6-LzaOOWr1ggJiuNgcEH3-6mXJjfI,13343
|
|
7
|
-
hdpws-0.6.25.dist-info/LICENSE,sha256=9VDxMcDDn3_T-sDQTMPxmiPZBDkPIiTO4OzYK5olDmk,12589
|
|
8
|
-
hdpws-0.6.25.dist-info/METADATA,sha256=CuAiLyMaDt_tx1k7X0cw-YHGESTXUppKtwUIm4A5B6I,3854
|
|
9
|
-
hdpws-0.6.25.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
|
10
|
-
hdpws-0.6.25.dist-info/top_level.txt,sha256=BTo-2sxU1YuKAD5Ykfc8bNQvgVX486A74voiQxV4NiQ,6
|
|
11
|
-
hdpws-0.6.25.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|