- FIX: commas in FBF-Fonbuch names
[vuplus_dvbapp-plugin] / fritzcall / src / __init__.py
1 # -*- coding: utf-8 -*-
2 from Components.config import config #@UnresolvedImport
3 import gettext
4 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE #@UnresolvedImport
5 try:
6         _ = gettext.translation('FritzCall', resolveFilename(SCOPE_PLUGINS, "Extensions/FritzCall/locale"), [config.osd.language.getText()]).gettext
7 except IOError:
8         pass
9
10 from time import localtime
11 def debug(message):
12         if config.plugins.FritzCall.debug.value:
13                 try:
14                         # ltim = localtime()
15                         # headerstr = u"%04d%02d%02d %02d:%02d " %(ltim[0],ltim[1],ltim[2],ltim[3],ltim[4])
16                         deb = open("/tmp/FritzDebug.log", "aw")
17                         # deb.write(headerstr + message.decode('utf-8') + u"\n")
18                         deb.write(message + "\n")
19                         deb.close()
20                 except:
21                         debug(repr(message) + " (retried debug)")
22                 
23
24 import re
25 def normalizePhoneNumber(intNo):
26         
27         found = re.match('^\+' + config.plugins.FritzCall.country.value.replace('00','') + '(.*)', intNo)
28         if found:
29                 intNo = '0' + found.group(1)
30         found = re.match('^\+(.*)', intNo)
31         if found:
32                 intNo = '00' + found.group(1)
33         intNo = intNo.replace('(', '').replace(')', '').replace(' ', '').replace('/', '').replace('-', '')
34         found = re.match('^49(.*)', intNo) # this is most probably an error
35         if found:
36                 intNo = '0' + found.group(1)
37         found = re.match('.*?([0-9]+)', intNo)
38         if found:
39                 return found.group(1)
40         else:
41                 return '0'