Commit cffd840d authored by Bernhard Geier's avatar Bernhard Geier
Browse files

improve XML parsing

make compatible to davical
parent e3e6584f
......@@ -5,7 +5,7 @@ That way Asterisk can show a caller's name instead of just the number.
If there's already an entry in Asterisk's caller database for a specific number, this script updates the number with the new name.
So far I have run this script successfully with OwnCloud 9 to Nextcloud 19.
So far I have run this script successfully with OwnCloud 9 to Nextcloud 21 and DAViCal 1.1.10.
### Requirements
* Python 3
......
......@@ -16,20 +16,16 @@ import configparser
# get list with links to all available vcards
def getAllVcardLinks(url, auth):
baseurl = urlparse(url).scheme+'://' + urlparse(url).netloc
baseurl = urlparse(url).scheme + '://' + urlparse(url).netloc
r = requests.request('PROPFIND', url, auth = auth)
r = requests.request('PROPFIND', url, auth = auth, headers={'content-type': 'text/xml', 'Depth': '1'})
if r.status_code != 207:
raise RuntimeError('error in response from %s: %r' % (url, r))
root = etree.XML(r.text)
vcardUrlList = []
for record in root.xpath(".//d:response", namespaces = {"d" : "DAV:"}):
type = record.xpath(".//d:getcontenttype", namespaces = {"d" : "DAV:"})
if (type) and type[0].text.startswith("text/vcard"):
vcardlinks = record.xpath(".//d:href", namespaces = {"d" : "DAV:"})
for link in vcardlinks:
vcardUrlList.append(baseurl + link.text)
root = etree.XML(r.text.encode())
for link in root.xpath('./d:response/d:propstat/d:prop/d:getcontenttype[starts-with(.,"text/vcard")]/../../../d:href', namespaces = {"d": "DAV:"}):
vcardUrlList.append(baseurl + link.text)
return vcardUrlList
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment