473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

pyext - google

tim
Hi,

I'm playing around with the python external for PureData. (pyext)
I want to enable a patch to lookup something on the net.
I modified the "search.py" example from Dive Into Python and kind of
pasted it into the simple.py example from the pyext docs to be loaded in
a pd patch.
Loading the script in the patch works, and it receives messages and
sends messages back, so I think on the pd side I've got it set up right.
If I call my "srch" function (see script) I get this error:

Traceback (most recent call last):
File "c:/pd/scripts\\searchggl.py", line 86, in srch_1
res = searchgoogle(q)
File "c:/pd/scripts\\searchggl.py", line 101, in searchgoogle
results = _server.doGoogleSearch(
File "C:\\Python24\\lib\\site-packages\\SOAPpy\\Client.py", line 470,
in __call__
return self.__r_call(*args, **kw)
File "C:\\Python24\\lib\\site-packages\\SOAPpy\\Client.py", line 492,
in __r_call
self.__hd, self.__ma)
File "C:\\Python24\\lib\\site-packages\\SOAPpy\\Client.py", line 406,
in __call
raise p
SOAPpy.Types.faultType: <Fault SOAP-ENV:Client: No Deserializer found to
deserialize a 'http://www.w3.org/1999/XMLSchema:Symbol' using encoding
style 'http://schemas.xmlsoap.org/soap/encoding/'.>

attached are the original search.py script, and my modified pd-pyext
version.

Any clues appreciated!
Tim

"""Search Google from the command line

This program is part of "Dive Into Python", a free Python book for
experienced programmers. Visit http://diveintopython.org/ for the
latest version.
"""

__author__ = "Mark Pilgrim (ma**@diveintopython.org)"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2004/05/20 18:53:59 $"
__copyright__ = "Copyright (c) 2004 Mark Pilgrim"
__license__ = "Python"

from SOAPpy import WSDL

# you'll need to configure these two values;
# see http://www.google.com/apis/
WSDLFILE = '/path/to/copy/of/GoogleSearch.wsdl'
APIKEY = 'YOUR_GOOGLE_API_KEY'

_server = WSDL.Proxy(WSDLFILE)
def search(q):
"""Search Google and return list of {title, link, description}"""
results = _server.doGoogleSearch(
APIKEY, q, 0, 10, False, "", False, "", "utf-8", "utf-8")
return [{"title": r.title.encode("utf-8"),
"link": r.URL.encode("utf-8"),
"description": r.snippet.encode("utf-8")}
for r in results.resultElements]

if __name__ == '__main__':
import sys
for r in search(sys.argv[1])[:5]:
print r['title']
print r['link']
print r['description']
print

# py/pyext - python script objects for PD and MaxMSP
#
# Copyright (c) 2002-2003 Thomas Grill (xo**@gmx.net)
# For information on usage and redistribution, and for a DISCLAIMER OF ALL
# WARRANTIES, see the file, "license.txt," in this distribution.
#

"""This is an example script for the py/pyext object's basic functionality.

pyext Usage:
- Import pyext

- Inherit your class from pyext._class

- Specfiy the number of inlets and outlets:
Use the class members (variables) _inlets and _outlets
If not given they default to 1
You can also use class methods with the same names to return the respective number

- Constructors/Destructors
You can specify an __init__ constructor and/or an __del__ destructor.
The constructor will be called with the object's arguments

e.g. if your PD or MaxMSP object looks like
[pyext script class arg1 arg2 arg3]

then the __init__(self,args) function will be called with a tuple argument
args = (arg1,arg2,arg3)
With this syntax, you will have to give at least one argument.
By defining the constructor as __init__(self,*args) you can also initialize
the class without arguments.

- Methods called by pyext
The general format is 'tag_inlet(self,args)' resp. 'tag_inlet(self,*args)':
tag is the PD or MaxMSP message header.. either bang, float, list etc.
inlet is the inlet (starting from 1) from which messages are received.
args is a tuple which corresponds to the content of the message. args can be omitted.

The inlet index can be omitted. The method name then has the format 'tag_(self,inlet,args)'.
Here, the inlet index is a additional parameter to the method

You can also set up methods which react on any message. These have the special forms
_anything_inlet(self,args)
or
_anything_(self,inlet,args)

Please see below for examples.

Any return values are ignored - use _outlet (see below).

Generally, you should avoid method_, method_xx forms for your non-pyext class methods.
Identifiers (variables and functions) with leading underscores are reserved for pyext.

- Send messages to outlets:
Use the inherited _outlet method.
You can either use the form
self._outlet(outlet,arg1,arg2,arg3,arg4) ... where all args are atoms (no sequence types!)
or
self._outlet(outlet,arg) ... where arg is a sequence containing only atoms

- Use pyext functions and methods:
See the __doc__ strings of the pyext module and the pyext._class base class.

"""

try:
import pyext
except:
print "ERROR: This script must be loaded by the PD/Max pyext external"

################################################## ###############

class srchg(pyext._class):
"""Example of a simple class which receives messages and prints to the console"""

# number of inlets and outlets
_inlets=3
_outlets=1
# methods for first inlet
def srch_1(self,q):
#return ('found')
self._outlet(1,'found')
res = searchgoogle(q)
self._outlet(1,res)

################################################## ###############

def searchgoogle(q):
from SOAPpy import WSDL

# you'll need to configure these two values;
# see http://www.google.com/apis/
WSDLFILE = 'c:\\Python24\\GoogleSearch.wsdl'
APIKEY = 'your_key_here'

_server = WSDL.Proxy(WSDLFILE)
"""Search Google and return list of {title, link, description}"""
results = _server.doGoogleSearch(
APIKEY, q, 0, 10, False, "", False, "", "utf-8", "utf-8")
return [{"title": r.title.encode("utf-8"),
"link": r.URL.encode("utf-8"),
"description": r.snippet.encode("utf-8")}
for r in results.resultElements]
Nov 27 '05 #1
0 1497

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: fuzzyman | last post by:
I've hacked together a 'GoogleCacheServer'. It is based on SimpleHTTPServer. Run the following script (hopefully google groups won't mangle the indentation) and set your browser proxy settings to...
3
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been...
25
by: Tor Erik Sønvisen | last post by:
Hi I need to browse the socket-module source-code. I believe it's contained in the file socketmodule.c, but I can't locate this file... Where should I look? regards tores
9
by: Ray5531 | last post by:
Sorry if this is irrelevant to this website,but I didn't find a better place to ask this question.I sent an email to google as well which I didn't recieve the answer.I'm creating a website and...
2
by: gen_tricomi | last post by:
THE IMPORTANCE OF MAKING THE GOOGLE INDEX DOWNLOADABLE I write here to make a request on behalf of all the programmers on earth who have been or are intending to use the Google web search API...
1
by: xahlee | last post by:
Elisp Tutorial: Make Google Earth Xah Lee, 2006-12 This page shows a example of writing a emacs lisp function that creates a Google Earth file, and creates a link to the file, as well a link...
16
by: Duncan Booth | last post by:
Google have announced a new service called 'Google App Engine' which may be of interest to some of the people here (although if you want to sign up you'll have to join the queue behind me): From...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.