E
Eric smith
In order to use the google data API without using (much) python,
I want to use Inline:ython.
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
I want to use Inline:ython.
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