def synonym(self, label): ''' Retreives the best PubChem id using a registered synonym CAS # is an example of a synonym that works well. ''' uri = _base + 'pug/compound/name/%s/xrefs/RegistryID/XML' % (label, ) xml = urlopen(uri).read() xml = xml.replace('xmlns=' + _pug_rest, '') order = pug_rest.CreateFromDOM(domutils.StringToDOM(xml)) o = order.Information[0].CID[0] self.cid = str(o)
def pubchem_xrefs(self, id): ''' Retrieves the external references, given a PubChem identifier ''' uri = _base + 'pug/compound/cid/%s/xrefs/SBURL/xml' % (id, ) xml = urlopen(uri).read() xml = xml.replace('xmlns=' + _pug_rest, '') order = pug_rest.CreateFromDOM(domutils.StringToDOM(xml)) o = order.Information[0] urls = o.SBURL self.urls = urls
import dict import urllib2 import pyxb.utils.domutils as domutils from xml.dom import minidom # Get the list of dictionaries available from the service. port_uri = 'http://services.aonaware.com/DictService/DictService.asmx' uri = port_uri + '/DictionaryList' dle_xml = urllib2.urlopen(uri).read() dle_dom = domutils.StringToDOM(dle_xml) dle = dict.ArrayOfDictionary.createFromDOM(dle_dom) op_path = '/DictionaryInfo' for d in dle.Dictionary: # Create a REST-style query to retrieve the information about this dictionary. uri = '%s%s?dictId=%s' % (port_uri, op_path, d.Id) resp = urllib2.urlopen(uri).read() # The response is a simple type derived from string, so we can # just extract and print it. di_resp = dict.CreateFromDOM(domutils.StringToDOM(resp)) # Do the "encode" garbage because one of these dictionaries has a # non-ASCII character print "%s (%s)\n%s\n" % (d.Name.encode('utf-8'), d.Id.encode('utf-8'), di_resp.encode('utf-8'))
# Override the position from the command line if 2 < len(sys.argv): lat = float(sys.argv[1]) lon = float(sys.argv[2]) # Import the schema bindings that were extracted from the WSDL in a # separate, previous step. import ndfd # Read in the WSDL spec for the service. Note that we have to process # the schema again here, because we were unable to save the component # model for it before, and we need the definition maps in order to # resolve part type references in the WSDL messages. import pyxb.bundles.wssplat.wsdl11 as wsdl uri_src = open('ndfdXML.wsdl') doc = domutils.StringToDOM(uri_src.read()) spec = wsdl.definitions.createFromDOM(doc.documentElement, process_schema=True) # Create a helper that will generate XML in the WSDL's namespace, # qualifying every element with xsi:type just like the service # expects. bds = domutils.BindingDOMSupport(default_namespace=spec.targetNamespace(), require_xsi_type=True) # Set the parameters that you want enabled. See # http://www.nws.noaa.gov/xml/docs/elementInputNames.php weather_params = ndfd.weatherParametersType(maxt=True, mint=True, temp=True, sky=True, pop12=True,
# Override the position from the command line if 2 < len(sys.argv): lat = float(sys.argv[1]) lon = float(sys.argv[2]) # Import the schema bindings that were extracted from the WSDL in a # separate, previous step. import ndfd # Read in the WSDL spec for the service. Note that we have to process # the schema again here, because we were unable to save the component # model for it before, and we need the definition maps in order to # resolve part type references in the WSDL messages. import pyxb.bundles.wssplat.wsdl11 as wsdl uri_src = open('ndfdXML.wsdl') doc = domutils.StringToDOM(uri_src.read()) spec = wsdl.definitions.createFromDOM(doc.documentElement, process_schema=True) # Create a helper that will generate XML in the WSDL's namespace, # qualifying every element with xsi:type just like the service # expects. bds = domutils.BindingDOMSupport(default_namespace=spec.targetNamespace(), require_xsi_type=True) # Set the parameters that you want enabled. See # http://www.nws.noaa.gov/xml/docs/elementInputNames.php weather_params = ndfd.weatherParametersType(maxt=True, mint=True, temp=True, sky=True, pop12=True, rh=True, wx=True, appt=True) # The schema didn't say the other parameters are optional (even though # they are), so set them to false if not already initialized. for eu in weather_params._ElementMap.values(): if eu.value(weather_params) is None:
from __future__ import print_function import time import urllib2 import weather # Bindings generated by PyXB import pyxb.utils.domutils as domutils uri = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityForecastByZIP?ZIP=55113' xml = urllib2.urlopen(uri).read() doc = domutils.StringToDOM(xml) fc_return = weather.CreateFromDOM(doc.documentElement) if fc_return.Success: print('Weather forecast for %s, %s:' % (fc_return.City, fc_return.State)) for fc in fc_return.ForecastResult.Forecast: when = time.strftime('%A, %B %d %Y', fc.Date.timetuple()) outlook = fc.Desciption # typos in WSDL left unchanged low = fc.Temperatures.MorningLow high = fc.Temperatures.DaytimeHigh print(' %s: %s, from %s to %s' % (when, outlook, low, high))
import dict import urllib2 import pyxb.utils.domutils as domutils import sys word = 'xml' if 1 < len(sys.argv): word = sys.argv[1] # Create a REST-style query to retrieve the information about this dictionary. uri = 'http://services.aonaware.com/DictService/DictService.asmx/Define?word=%s' % ( word, ) rxml = urllib2.urlopen(uri).read() resp = dict.CreateFromDOM(domutils.StringToDOM(rxml)) print 'Definitions of %s:' % (resp.Word, ) for definition in resp.Definitions.Definition: print 'From %s (%s):' % (definition.Dictionary.Name, definition.Dictionary.Id) print definition.WordDefinition print