neingeist
/
smstool
Archived
1
0
Fork 0

Get contacts from Evolution

master
neingeist 20 years ago
parent 221daf0363
commit 0240cbbb66

@ -1,10 +1,42 @@
#!/usr/bin/python #!/usr/bin/python
from wxPython.wx import * from wxPython.wx import *
from os import system import bsddb
from re import sub import os
import re
# Constants
SMSLEN = 160 SMSLEN = 160
DB_PATH = "~/.evolution/addressbook/local/system/addressbook.db"
# EvolutionsCells gets cell phone numbers out of the Evolution database
class EvolutionCells:
def __init__(self):
contacts = {}
self.contacts = contacts
db = bsddb.hashopen(os.path.expanduser(DB_PATH),"r")
self.db = db
for k in db.keys():
name = ""
cell = ""
for e in db[k].split('\r\n'):
if re.search("^FN:", e):
name = re.sub("^FN:", "", e)
if re.search("^TEL;TYPE=CELL:", e):
cell = re.sub("^TEL;TYPE=CELL:", "", e)
if cell != "":
contacts[name] = cell
db.close
def getContacts(self):
return self.contacts
# SimserFrame is the application
class SimserFrame(wxFrame): class SimserFrame(wxFrame):
def __init__(self, parent, id, title): def __init__(self, parent, id, title):
@ -18,7 +50,7 @@ class SimserFrame(wxFrame):
wxStaticText(panel, -1, "Text:", wxStaticText(panel, -1, "Text:",
wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize) wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize)
wxStaticText(panel, -1, "Nummer:", wxStaticText(panel, -1, "Contact:",
wxDLG_PNT(panel, wxPoint(4, 20)), wxDefaultSize) wxDLG_PNT(panel, wxPoint(4, 20)), wxDefaultSize)
self.textCtrl = wxTextCtrl(panel, 20, "", self.textCtrl = wxTextCtrl(panel, 20, "",
@ -27,11 +59,7 @@ class SimserFrame(wxFrame):
self.textCtrl.SetMaxLength(SMSLEN); self.textCtrl.SetMaxLength(SMSLEN);
self.textCtrl.SetFocus() self.textCtrl.SetFocus()
self.nrCtrl = wxTextCtrl(panel, -1, "", self.sendCtrl = wxButton(panel, 10, "Send",
wxDLG_PNT(panel, wxPoint(30, 20)),
wxDLG_SZE(panel, wxSize(60, -1)))
self.sendCtrl = wxButton(panel, 10, "Senden",
wxDLG_PNT(panel, wxPoint(100, 20)), wxDLG_PNT(panel, wxPoint(100, 20)),
wxDLG_SZE(panel, wxSize(30, -1))) wxDLG_SZE(panel, wxSize(30, -1)))
EVT_BUTTON(self, 10, self.OnSendClick) EVT_BUTTON(self, 10, self.OnSendClick)
@ -41,22 +69,48 @@ class SimserFrame(wxFrame):
EVT_TEXT(self, 20, self.OnChange) EVT_TEXT(self, 20, self.OnChange)
# Get contacts
cells = EvolutionCells()
self.contacts = cells.getContacts()
# Fill contact list and the combobox
contactlist = self.contacts.keys()
contactlist.sort()
self.contactCtrl = wxComboBox(panel, -1, contactlist[0],
wxDLG_PNT(panel, wxPoint(30, 20)),
wxDLG_SZE(panel, wxSize(60, -1)),
contactlist)
def OnCloseWindow(self, event): def OnCloseWindow(self, event):
self.Destroy() self.Destroy()
def OnSendClick(self, event): def OnSendClick(self, event):
text = self.textCtrl.GetValue() text = self.textCtrl.GetValue()
nr = self.nrCtrl.GetValue() contact = self.contactCtrl.GetValue()
# Figure out if we have a number or a name
if re.search('^[+0-9]+$', contact):
nr = contact
else:
if self.contacts.has_key(contact):
nr = self.contacts[contact]
else:
self.foodialog = wxMessageDialog(self.panel,
"Contact '" + contact + "' is unknown!",
"Erros", wxOK, wxPoint(100, 100))
self.foodialog.Show(true)
return
# Quote text # Quote text
text = sub("'", "''", text) text = re.sub("'", "''", text)
nr = sub("'", "''", nr) nr = re.sub("'", "''", nr)
# Send SMS and report back # Send SMS and report back
rc = system("echo '" + text + "' | gsmsendsms '" + nr + "'") rc = os.system("echo '" + text + "' | gsmsendsms '" + nr + "'")
if(rc == 0): if(rc == 0):
self.foodialog = wxMessageDialog(self.panel, self.foodialog = wxMessageDialog(self.panel,
"Message sent", "Message sent to " + nr,
"Success", wxOK, wxPoint(100, 100)) "Success", wxOK, wxPoint(100, 100))
else: else:
self.foodialog = wxMessageDialog(self.panel, self.foodialog = wxMessageDialog(self.panel,