#!/usr/bin/env python import pprint import gammu import time from AccountBalance import getAccountBalance # debug pp = pprint.PrettyPrinter(indent=4) verbose = True def Callback(sm, type, data): if verbose: print 'Received incoming event type %s, data:' % type if type != 'SMS': print 'Unsupported event!' if not data.has_key('Number'): data = sm.GetSMS(data['Folder'], data['Location'])[0] if verbose: print data balance = getAccountBalance() replyMessage = {'Text': balance, 'SMSC': {'Location': 1}, 'Number': data['Number']} sm.SendSMS(replyMessage) sm = gammu.StateMachine() sm.ReadConfig() sm.Init() sm.SetIncomingCallback(Callback) try: sm.SetIncomingSMS() except gammu.ERR_NOTSUPPORTED: print 'Your phone does not support incoming SMS notifications!' # We need to keep communication with phone to get notifications print 'Press Ctrl+C to interrupt' while 1: time.sleep(1) status = sm.GetBatteryCharge() print 'Battery is at %d%%' % status['BatteryPercent']