Skip to content

Commit 31bc7e6

Browse files
committed
first commit
0 parents  commit 31bc7e6

4 files changed

Lines changed: 101 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
dist
3+
*.pyc

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build_app:
2+
rm -rf build dist
3+
python setup.py py2app

clicktoshell.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import sys
2+
import os
3+
import re
4+
5+
6+
def clean_phone(data):
7+
""" Returns an international phone number for many common formats """
8+
9+
simplified = data.strip()
10+
11+
# Us phone numbers: (217) 352-1913
12+
if re.search(r"^\([0-9]{3}\)\s*[0-9]{3}\s*\-\s*[0-9]{4}$", simplified):
13+
simplified = "+1" + simplified
14+
15+
# Us phone numbers: 217-352-1913
16+
if re.search(r"^[0-9]{3}\s*\-\s*[0-9]{3}\s*\-\s*[0-9]{4}$", simplified):
17+
simplified = "+1" + simplified
18+
19+
# Manage phones like +32 (0) 80 41 81 54
20+
if simplified.startswith("+"):
21+
simplified = re.sub(r"\(\s*0\s*\)", "", simplified)
22+
23+
simplified = re.sub(r"[\(\)\-\.\s]", "", simplified)
24+
25+
# Special case for phones like 33 (0)4 89 06 58 00
26+
if simplified.startswith("330") and len(simplified) == 12:
27+
simplified = "+33" + simplified[3:]
28+
29+
# 33 1 346 678 32
30+
if simplified.startswith("33") and len(simplified) == 11:
31+
simplified = "+33" + simplified[2:]
32+
33+
# 44 7918708773
34+
if simplified.startswith("44") and len(simplified) == 12:
35+
simplified = "+" + simplified
36+
37+
# (+33) 09 81 01 99 31
38+
if simplified.startswith("+330"):
39+
simplified = "+33" + simplified[4:]
40+
41+
if re.search(r"^\+?[0-9]{6,15}$", simplified):
42+
if simplified.startswith("00"):
43+
simplified = "+" + simplified[2:]
44+
elif simplified.startswith("0"):
45+
simplified = "+33" + simplified[1:] # Historical french default
46+
47+
return simplified
48+
49+
return None
50+
51+
52+
protocol, raw_phone = sys.argv[1].split(":", 1)
53+
54+
template_file = os.path.expanduser("~/clicktoshell-%s.sh" % protocol)
55+
56+
phone = clean_phone(raw_phone)
57+
58+
if os.path.isfile(template_file):
59+
os.system("sh %s '%s'" % (template_file, phone))

setup.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
This is a setup.py script generated by py2applet
3+
4+
Usage:
5+
python setup.py py2app
6+
"""
7+
8+
from setuptools import setup
9+
10+
APP = ['clicktoshell.py']
11+
DATA_FILES = []
12+
OPTIONS = {
13+
'argv_emulation': True,
14+
'plist' : {
15+
'CFBundleDevelopmentRegion' : 'en',
16+
'NSPrincipalClass' : 'NSApplication',
17+
'NSAppleScriptEnabled' : 'YES',
18+
'LSUIElement' : 'YES',
19+
'CFBundleIdentifier' : 'com.pricingassistant.clicktoshell',
20+
'CFBundleURLTypes' : [{
21+
'CFBundleURLName' : 'Click To Shell',
22+
'CFBundleURLSchemes' : [
23+
'callto',
24+
'tel',
25+
'sms'
26+
]
27+
}]
28+
}
29+
}
30+
31+
setup(
32+
app=APP,
33+
data_files=DATA_FILES,
34+
options={'py2app': OPTIONS},
35+
setup_requires=['py2app'],
36+
)

0 commit comments

Comments
 (0)