@@ -230,30 +230,8 @@ def list_instruments(self, cache=True):
230230 self ._instrument_list .append (u'harps' )
231231 return self ._instrument_list
232232
233- def list_surveys (self , cache = True ):
234- """ List all the available surveys (phase 3) in the ESO archive.
235-
236- Returns
237- -------
238- survey_list : list of strings
239- cache : bool
240- Cache the response for faster subsequent retrieval
241-
242- """
243- if self ._survey_list is None :
244- survey_list_response = self ._request (
245- "GET" , "http://archive.eso.org/wdb/wdb/adp/phase3_main/form" ,
246- cache = cache )
247- root = BeautifulSoup (survey_list_response .content , 'html5lib' )
248- self ._survey_list = []
249- for select in root .select ("select[name=phase3_program]" ):
250- for element in select .select ('option' ):
251- survey = element .text .strip ()
252- if survey not in self ._survey_list and 'Any' not in survey :
253- self ._survey_list .append (survey )
254- return self ._survey_list
255-
256- def query_survey (self , survey , cache = True , ** kwargs ):
233+ def query_surveys (self , surveys = 'any_collection_id' , cache = True ,
234+ help = False , ** kwargs ):
257235 """
258236 Query survey Phase 3 data contained in the ESO archive.
259237
@@ -276,13 +254,11 @@ def query_survey(self, survey, cache=True, **kwargs):
276254
277255 """
278256
279- if survey not in self .list_surveys ():
280- raise ValueError ("Survey %s is not in the survey list." % survey )
281257 url = "http://archive.eso.org/wdb/wdb/adp/phase3_main/form"
282258 survey_form = self ._request ("GET" , url , cache = cache )
283259 query_dict = kwargs
284260 query_dict ["wdbo" ] = "csv/download"
285- query_dict ['phase3_program ' ] = survey
261+ query_dict ['collection_name ' ] = surveys
286262 if self .ROW_LIMIT >= 0 :
287263 query_dict ["max_rows_returned" ] = self .ROW_LIMIT
288264 else :
@@ -345,7 +321,7 @@ def query_instrument(self, instrument, column_filters={}, columns=[],
345321 if open_form :
346322 webbrowser .open (url )
347323 elif help :
348- self ._print_help (url , instrument )
324+ self ._print_instrument_help (url , instrument )
349325 else :
350326 instrument_form = self ._request ("GET" , url , cache = cache )
351327 query_dict = {}
@@ -618,7 +594,7 @@ def query_apex_quicklooks(self, project_id=None, help=False,
618594 if open_form :
619595 webbrowser .open (apex_query_url )
620596 elif help :
621- return self ._print_help (apex_query_url , 'apex' )
597+ return self ._print_instrument_help (apex_query_url , 'apex' )
622598 else :
623599
624600 payload = {'wdbo' : 'csv/download' }
@@ -643,7 +619,7 @@ def query_apex_quicklooks(self, project_id=None, help=False,
643619
644620 return table
645621
646- def _print_help (self , url , instrument , cache = True ):
622+ def _print_instrument_help (self , url , instrument , cache = True ):
647623 """
648624 Download a form and print it in a quasi-human-readable way
649625 """
@@ -700,4 +676,81 @@ def _print_help(self, url, instrument, cache=True):
700676 print ("\n " .join (result_string ))
701677 return result_string
702678
679+ def _print_surveys_help (self , url , cache = True ):
680+ """
681+ Download a form and print it in a quasi-human-readable way
682+ """
683+ log .info ("List of the parameters accepted by the "
684+ "surveys query." )
685+ log .info ("The presence of a column in the result table can be "
686+ "controlled if prefixed with a [ ] checkbox." )
687+ log .info ("The default columns in the result table are shown as "
688+ "already ticked: [x]." )
689+
690+ result_string = []
691+
692+ resp = self ._request ("GET" , url , cache = cache )
693+ doc = BeautifulSoup (resp .content , 'html5lib' )
694+ form = doc .select ("html body form" )[0 ]
695+
696+ # hovertext from different labels are used to give more info on forms
697+ helptext_dict = {abbr ['title' ].split (":" )[0 ].strip ():
698+ ":" .join (abbr ['title' ].split (":" )[1 :])
699+ for abbr in form .findAll ('abbr' )
700+ if 'title' in abbr .attrs and ":" in abbr ['title' ]}
701+
702+ for fieldset in form .select ('fieldset' ):
703+ legend = fieldset .select ('legend' )
704+ if len (legend ) > 1 :
705+ raise ValueError ("Form parsing error: too many legends." )
706+ elif len (legend ) == 0 :
707+ continue
708+ section_title = "\n \n " + "" .join (legend [0 ].stripped_strings )+ "\n "
709+
710+ result_string .append (section_title )
711+
712+ for section in fieldset .select ('table' ):
713+
714+ checkbox_name = ""
715+ checkbox_value = ""
716+ for tag in section .next_elements :
717+ if tag .name == u"table" :
718+ break
719+ elif tag .name == u"input" :
720+ if tag .get (u'type' ) == u"checkbox" :
721+ checkbox_name = tag ['name' ]
722+ checkbox_value = (u"[x]"
723+ if ('checked' in tag .attrs )
724+ else u"[ ]" )
725+ name = ""
726+ value = ""
727+ else :
728+ name = tag ['name' ]
729+ value = ""
730+ elif tag .name == u"select" :
731+ options = []
732+ for option in tag .select ("option" ):
733+ options += ["{0} ({1})"
734+ .format (option ['value' ]
735+ if 'value' in option
736+ else "" ,
737+ "" .join (option .stripped_strings ))]
738+ name = tag [u"name" ]
739+ value = ", " .join (options )
740+ else :
741+ name = ""
742+ value = ""
743+ if u"tab_" + name == checkbox_name :
744+ checkbox = checkbox_value
745+ else :
746+ checkbox = " "
747+ if name != u"" :
748+ result_string .append ("{0} {1}: {2}"
749+ .format (checkbox , name , value ))
750+ if name .strip () in helptext_dict :
751+ result_string .append (helptext_dict [name .strip ()])
752+
753+ print ("\n " .join (result_string ))
754+ return result_string
755+
703756Eso = EsoClass ()
0 commit comments