??????Asterisk

? gmail ??????? Asterisk CID ?????? googlecontacts.py

#!/usr/bin/python # googlecontacts.py v0.1 # By: John Baab # Email: [email protected] # MODIFIED by : Raphael # Purpose: syncs contacts from to asterisk server # Requirements: python, gdata python , asterisk # # License: # # This Package is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 3 of the License, or (at your option) any later version. # # This package is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this package; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # On Debian & Ubuntu systems, a complete copy of the GPL can be found under # /usr/share/common-licenses/GPL-3, or (at your option) any later version import ,re,sys,os import gdata.contacts import gdata.contacts.service def main():

gd_client = gdata.contacts.service.ContactsService() gd_client.email = "[email protected]" gd_client.password = "PASSWORD" gd_client.source = 'gcontact2ast' gd_client.ProgrammaticLogin() query = gdata.contacts.service.ContactsQuery() query.max_results = 1000 feed = gd_client.GetContactsFeed(query.ToUri())

# delete all of our contacts before we refetch them, this will allow deletions os.system("asterisk -rx \'database deltree cidname\'")

1 GMail ??????Asterisk

# for each phone number in the contacts for i, entry in enumerate(feed.entry): for phone in entry.phone_number: # Strip out any non numeric characters phone.text = re.sub('\D', '', phone.text)

# Insert the number into the cidname database, reinsert the 00 (international)code.

os.system("asterisk -rx \'database put cidname 00%s \"%s\"\'" % (phone.text,entry.title.text)) if __name__ == "__main__": main()

2