使 gmail 的通訊錄可以與 Asterisk CID 資料庫做同步
googlecontacts.py
#!/usr/bin/python # googlecontacts.py v0.1 # By: John Baab # Email: rhpot1991@ubuntu.com # MODIFIED by : Raphael # Purpose: syncs contacts from google to asterisk server # Requirements: python, gdata python client, 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 atom,re,sys,os import gdata.contacts import gdata.contacts.service def main(): gd_client = gdata.contacts.service.ContactsService() gd_client.email = "EMAILl@gmail.com" 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\'") # 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()
Images 0 | ||
---|---|---|
No images to display in the gallery. |