Inline::Python

E

Eric smith

In order to use the google data API without using (much) python,
I want to use Inline::python.

The following code works, however, I do not know how to call the
function CreateEntry() from the ContactsSample class in
the perl code.

Thanks for any help with this.

Eric Smith


#!/usr/bin/perl

print "Hello from perl\n";

use Inline Python => <<'END_OF_PYTHON_CODE';
import sys
import getopt
import getpass
import atom
import gdata.contacts
import gdata.contacts.service

class ContactsSample(object):
"""ContactsSample object demonstrates operations with the Contacts feed."""

def __init__(self, email, password):
"""Constructor for the ContactsSample object."""

self.gd_client = gdata.contacts.service.ContactsService()
self.gd_client.email = email
self.gd_client.password = password
self.gd_client.source = 'GoogleInc-ContactsPythonSample-1'
self.gd_client.ProgrammaticLogin()

def CreateEntry(self):
name = 'John Doe''
notes = "Something about him"
primary_email = '(e-mail address removed)'

new_contact = gdata.contacts.ContactEntry(title=atom.Title(text=name))
new_contact.content = atom.Content(text=notes)
new_contact.email.append(gdata.contacts.Email(address=primary_email,
primary='true', rel=gdata.contacts.REL_WORK))
entry = self.gd_client.CreateContact(new_contact)

if entry:
print 'Creation successful!'

def Run(self):
self.CreateEntry()

def main():

user = 'XXXXXXXXX'
pw = 'XXXXXXXX'

try:
sample = ContactsSample(user, pw)
except gdata.service.BadAuthentication:
print 'Invalid user credentials given.'
return

sample.Run()

if __name__ == '__main__':
main()
END_OF_PYTHON_CODE
 
E

Eric smith

Thanks Ben, but no dice alas.

I also tried this from the manual:
py_bind_class("Inline::python", "__main__", "ContactsSample",\
"set_data", "get_data");
my $o = new ContactsSample;

Both respond with:
Can't locate object method "new" via package "ContactsSample"

Any suggestions / help?

Thanks

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top