Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bridge.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ url2 = https://www.example.com/oc/remote.php/dav/addressbooks/users/xyz/456
[www.myserver.org]
user = username
pass = ****
url1 = https://www.myserver.org/oc/remote.php/dav/addressbooks/users/xyz/123
url1 = https://www.myserver.org/oc/remote.php/dav/addressbooks/users/xyz/123

[local-file]
file1 = contacts-2025-01-01.vcf
file2 = C:\Temp\contacts-2025-02-02.vcf
25 changes: 20 additions & 5 deletions bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
# This script generates Contacts.xml valid for MicroSIP VoIP client v3.10
# ---------------------------------------------------------------------------

import codecs
import configparser
import os
import re
Expand All @@ -45,16 +44,16 @@
__url__ = 'https://github.com/gitRigge/CardDAV2MicroSIP'
__license__ = 'MIT License (MIT)'

microSipDataPath = os.environ['APPDATA']+'\MicroSIP'
bridgeDataPath = os.environ['LOCALAPPDATA']+'\CardDAV2MicroSIP'
microSipDataPath = os.path.join(os.environ['APPDATA'], 'MicroSIP')
bridgeDataPath = os.path.join(os.environ['LOCALAPPDATA'], 'CardDAV2MicroSIP')
bridge_config = configparser.ConfigParser()
bridge_config.read(os.path.join(bridgeDataPath, 'bridge.conf'))
microsip_config = configparser.ConfigParser()
microsip_config.read_file(codecs.open(os.path.join(microSipDataPath, 'microsip.ini'), 'r', 'utf16'))
microsip_config.read_file(open(os.path.join(microSipDataPath, 'microsip.ini'), 'r', encoding='utf16'))

def get_country_code():
"""Tries to find country code info in MicroSIP config file and returns it."""
p = re.compile('(\+[0-9]{1,3})')
p = re.compile(r'(\+[0-9]{1,3})')
for section in microsip_config.sections():
if microsip_config.has_option(section,'dialPlan'):
m = p.search(microsip_config.get(section,'dialPlan'))
Expand All @@ -68,19 +67,35 @@ def get_carddav_data():
servers = bridge_config.sections()
counter = 1
for server in servers:
print("Reading ", server, " from servers.")
accounts[counter] = {}
_urls = []
_files = []
for key in bridge_config[server]:
if key == 'user':
accounts[counter]['user'] = bridge_config[server]['user']
elif key == 'pass':
accounts[counter]['pass'] = bridge_config[server]['pass']
elif key.startswith('url'):
_urls.append(bridge_config[server][key])
elif key.startswith('file'):
_files.append(bridge_config[server][key])
accounts[counter]['url'] = _urls
accounts[counter]['file'] = _files
counter = counter + 1
contents = ''
for account in accounts:
print("Processing ", account, " from servers.")
for abook in accounts[account]['file']:
try:
if os.path.exists(abook):
with open(abook, 'r', encoding='utf8') as file:
content = file.read()
contents = contents + content
else:
print("File ", abook, " not found! Please check bridge.conf.")
except:
continue
for abook in accounts[account]['url']:
try:
response = requests.get(abook+'/?export', auth = HTTPBasicAuth(accounts[account]['user'], accounts[account]['pass']))
Expand Down