77"""
88
99import warnings
10- # example warning
11- # warnings.warn("Band was specified, so blabla is overridden")
12- #~ from astropy.io import ascii
13- #~ from astropy import units as u
1410from ..query import BaseQuery
1511from ..utils import commons , async_to_sync
16- #~ from ..utils.docstr_chompers import prepend_docstr_noreturns
1712from . import conf
18- #~ from .utils import *
1913from astropy .table import Table , Column
2014
2115from ..utils .class_or_instance import class_or_instance
2216from ..utils import commons , async_to_sync
2317from .utils import *
24- #~ from BeautifulSoup import BeautifulSoup as bfs
2518
2619from xml .dom import minidom
2720
2821__all__ = ['ADS' , 'ADSClass' ]
2922
3023@async_to_sync
3124class ADSClass (BaseQuery ):
32-
33- ####### FROM SPLATALOGUE
25+
3426 SERVER = conf .server
3527 QUERY_ADVANCED_PATH = conf .advanced_path
3628 QUERY_SIMPLE_PATH = conf .simple_path
@@ -39,7 +31,6 @@ class ADSClass(BaseQuery):
3931 QUERY_SIMPLE_URL = SERVER + QUERY_SIMPLE_PATH
4032 QUERY_ADVANCED_URL = SERVER + QUERY_ADVANCED_PATH
4133
42- ######## FROM API DOCS
4334 def __init__ (self , * args ):
4435 """ set some parameters """
4536 pass
@@ -50,17 +41,14 @@ def query_simple(self, query_string, get_query_payload=False, get_raw_response=F
5041 request_payload = self ._args_to_payload (query_string )
5142
5243 response = commons .send_request (self .QUERY_SIMPLE_URL , request_payload , self .TIMEOUT )
53-
44+
5445 # primarily for debug purposes, but also useful if you want to send
5546 # someone a URL linking directly to the data
5647 if get_query_payload :
5748 return request_payload
5849 if get_raw_response :
5950 return response
60- # parse the XML response into Beautiful Soup
61- #~ response_bfs = self._parse_response_to_bfs(response)
62- #
63- #self._parse_bfs_to_table(response_bfs)
51+ # parse the XML response into AstroPy Table
6452 resulttable = self ._parse_response (response .encode (results .encoding ).decode ('utf-8' ))
6553
6654 return resulttable
@@ -73,22 +61,20 @@ def _parse_response(self, response):
7361 hitlist = xmlrepr .childNodes [0 ].childNodes
7462 hitlist = hitlist [1 ::2 ] # every second hit is a "line break"
7563
76- # Parse the results
77- # first single items
78- titles = get_data_from_xml (hitlist , 'title' )
79- bibcode = get_data_from_xml (hitlist , 'bibcode' )
80- journal = get_data_from_xml (hitlist , 'journal' )
81- volume = get_data_from_xml (hitlist , 'volume' )
82- pubdate = get_data_from_xml (hitlist , 'pubdate' )
83- page = get_data_from_xml (hitlist , 'page' )
84- score = get_data_from_xml (hitlist , 'score' )
85- citations = get_data_from_xml (hitlist , 'citations' )
86- abstract = get_data_from_xml (hitlist , 'abstract' )
87- doi = get_data_from_xml (hitlist , 'DOI' )
88- eprintid = get_data_from_xml (hitlist , 'eprintid' )
89- #~ = get_data_from_xml(hitlist, '')
90- authors = get_data_from_xml (hitlist , 'author' )
91-
64+ # Grab the various fields
65+ titles = _get_data_from_xml (hitlist , 'title' )
66+ bibcode = _get_data_from_xml (hitlist , 'bibcode' )
67+ journal = _get_data_from_xml (hitlist , 'journal' )
68+ volume = _get_data_from_xml (hitlist , 'volume' )
69+ pubdate = _get_data_from_xml (hitlist , 'pubdate' )
70+ page = _get_data_from_xml (hitlist , 'page' )
71+ score = _get_data_from_xml (hitlist , 'score' )
72+ citations = _get_data_from_xml (hitlist , 'citations' )
73+ abstract = _get_data_from_xml (hitlist , 'abstract' )
74+ doi = _get_data_from_xml (hitlist , 'DOI' )
75+ eprintid = _get_data_from_xml (hitlist , 'eprintid' )
76+ authors = _get_data_from_xml (hitlist , 'author' )
77+ # put into AstroPy Table
9278 t = Table ()
9379 t ['title' ] = titles
9480 t ['bibcode' ] = bibcode
@@ -112,69 +98,4 @@ def _args_to_payload(self, query_string):
11298
11399
114100
115- ADS = ADSClass ()
116-
117-
118- """
119- typical fields available:
120-
121- [u'bibcode',
122- u'title',
123- u'author',
124- u'author',
125- u'author',
126- u'affiliation',
127- u'journal',
128- u'volume',
129- u'pubdate',
130- u'page',
131- u'keywords',
132- u'keyword',
133- u'keyword',
134- u'keyword',
135- u'keyword',
136- u'keyword',
137- u'origin',
138- u'link',
139- u'name',
140- u'url',
141- u'link',
142- u'name',
143- u'url',
144- u'link',
145- u'name',
146- u'url',
147- u'link',
148- u'name',
149- u'url',
150- u'link',
151- u'name',
152- u'url',
153- u'count',
154- u'link',
155- u'name',
156- u'url',
157- u'count',
158- u'link',
159- u'name',
160- u'url',
161- u'count',
162- u'link',
163- u'name',
164- u'url',
165- u'link',
166- u'name',
167- u'url',
168- u'count',
169- u'link',
170- u'name',
171- u'url',
172- u'url',
173- u'score',
174- u'citations',
175- u'abstract',
176- u'doi',
177- u'eprintid']
178-
179-
180- """
101+ ADS = ADSClass ()
0 commit comments