neingeist
/
smstool
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

136 lines
3.7 KiB
Python

#!/usr/bin/python
19 years ago
import wxversion
#wxversion.select("2.5")
20 years ago
from wxPython.wx import *
import bsddb
import os
import re
# Constants
20 years ago
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
20 years ago
class SimserFrame(wxFrame):
20 years ago
def __init__(self, parent, id, title):
# Create GUI
20 years ago
wxFrame.__init__(self, parent, id, title,
wxPoint(100, 100), wxSize(450, 70))
panel = wxPanel(self, -1)
self.panel = panel
wxStaticText(panel, -1, "Text:",
wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize)
wxStaticText(panel, -1, "Contact:",
20 years ago
wxDLG_PNT(panel, wxPoint(4, 20)), wxDefaultSize)
20 years ago
self.textCtrl = wxTextCtrl(panel, 20, "",
20 years ago
wxDLG_PNT(panel, wxPoint(30, 4)),
wxDLG_SZE(panel, wxSize(160, -1)))
20 years ago
self.textCtrl.SetMaxLength(SMSLEN);
self.textCtrl.SetFocus()
20 years ago
self.sendCtrl = wxButton(panel, 10, "Send",
wxDLG_PNT(panel, wxPoint(100, 20)),
20 years ago
wxDLG_SZE(panel, wxSize(30, -1)))
EVT_BUTTON(self, 10, self.OnSendClick)
20 years ago
20 years ago
self.zaehler = wxStaticText(panel, -1, str(SMSLEN),
wxDLG_PNT(panel, wxPoint(150, 20)), wxDefaultSize)
20 years ago
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)
20 years ago
20 years ago
def OnCloseWindow(self, event):
self.Destroy()
def OnSendClick(self, event):
20 years ago
text = self.textCtrl.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
20 years ago
# Quote text
text = re.sub("'", "''", text)
nr = re.sub("'", "''", nr)
# Send SMS and report back
rc = os.system("echo '" + text + "' | gsmsendsms '" + nr + "'")
if(rc == 0):
self.foodialog = wxMessageDialog(self.panel,
"Message sent to " + nr,
"Success", wxOK, wxPoint(100, 100))
else:
self.foodialog = wxMessageDialog(self.panel,
"gsmsendsms returned error code: " + str(rc >> 8),
"Error", wxOK, wxPoint(100, 100))
20 years ago
self.foodialog.Show(true)
def OnChange(self, event):
self.zaehler.SetLabel(str(SMSLEN-len(self.textCtrl.GetValue())))
20 years ago
class Simser(wxApp):
20 years ago
def OnInit(self):
frame = SimserFrame(NULL, -1, "Simser")
20 years ago
frame.Show(true)
self.SetTopWindow(frame)
return true
smstool=Simser(0)
20 years ago
smstool.MainLoop()