Package Skype4Py :: Module sms
[frames] | no frames]

Source Code for Module Skype4Py.sms

  1  '''Short messaging to cell phones. 
  2  ''' 
  3   
  4  from utils import * 
  5   
  6   
7 -class ISmsChunk(Cached):
8 '''Represents a single chunk of a multi-part SMS message. 9 ''' 10
11 - def __repr__(self):
12 return '<%s with Id=%s, Message=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id), repr(self.Message))
13
14 - def _Init(self, Id_Message):
15 Id, Message = Id_Message 16 self._Id = int(Id) 17 self._Message = Message
18
19 - def _GetCharactersLeft(self):
20 count, left = map(int, chop(self._Message._Property('CHUNKING', Cache=False))) 21 if self._Id == count - 1: 22 return left 23 return 0
24 25 CharactersLeft = property(_GetCharactersLeft, 26 doc='''CharactersLeft. 27 28 @type: int 29 ''') 30
31 - def _GetId(self):
32 return self._Id
33 34 Id = property(_GetId, 35 doc='''SMS chunk Id. 36 37 @type: int 38 ''') 39
40 - def _GetMessage(self):
41 return self._Message
42 43 Message = property(_GetMessage, 44 doc='''SMS message associated with this chunk. 45 46 @type: L{ISmsMessage} 47 ''') 48
49 - def _GetText(self):
50 return self._Message._Property('CHUNK %s' % self._Id)
51 52 Text = property(_GetText, 53 doc='''Text (body) of this SMS chunk. 54 55 @type: unicode 56 ''')
57 58
59 -class ISmsMessage(Cached):
60 '''Represents an SMS message. 61 ''' 62
63 - def __repr__(self):
64 return '<%s with Id=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id))
65
66 - def _Alter(self, AlterName, Args=None):
67 return self._Skype._Alter('SMS', self._Id, AlterName, Args)
68
69 - def _Init(self, Id, Skype):
70 self._Id = int(Id) 71 self._Skype = Skype
72
73 - def _Property(self, PropName, Set=None, Cache=True):
74 return self._Skype._Property('SMS', self._Id, PropName, Set, Cache)
75
76 - def Delete(self):
77 '''Deletes this SMS message. 78 ''' 79 self._Skype._DoCommand('DELETE SMS %s' % self._Id)
80
81 - def Send(self):
82 '''Sends this SMS message. 83 ''' 84 self._Alter('SEND')
85
86 - def _GetBody(self):
87 return self._Property('BODY')
88
89 - def _SetBody(self, value):
90 self._Property('BODY', value)
91 92 Body = property(_GetBody, _SetBody, 93 doc='''Text of this SMS message. 94 95 @type: unicode 96 ''') 97
98 - def _GetChunks(self):
99 return tuple([ISmsChunk((x, self)) for x in range(int(chop(self._Property('CHUNKING', Cache=False))[0]))])
100 101 Chunks = property(_GetChunks, 102 doc='''Chunks of this SMS message. More than one if this is a multi-part message. 103 104 @type: tuple of L{ISmsChunk} 105 ''') 106
107 - def _GetDatetime(self):
108 from datetime import datetime 109 return datetime.fromtimestamp(self.Timestamp)
110 111 Datetime = property(_GetDatetime, 112 doc='''Timestamp of this SMS message as datetime object. 113 114 @type: datetime.datetime 115 ''') 116
117 - def _GetFailureReason(self):
118 return self._Property('FAILUREREASON')
119 120 FailureReason = property(_GetFailureReason, 121 doc='''Reason an SMS message failed. Read this if L{Status} == L{smsMessageStatusFailed<enums.smsMessageStatusFailed>}. 122 123 @type: L{SMS failure reason<enums.smsFailureReasonUnknown>} 124 ''') 125
126 - def _GetId(self):
127 return self._Id
128 129 Id = property(_GetId, 130 doc='''Unique SMS message Id. 131 132 @type: int 133 ''') 134
135 - def _GetIsFailedUnseen(self):
136 return self._Property('IS_FAILED_UNSEEN') == 'TRUE'
137 138 IsFailedUnseen = property(_GetIsFailedUnseen, 139 doc='''Tells if a failed SMS message was unseen. 140 141 @type: bool 142 ''') 143
144 - def _GetPrice(self):
145 return int(self._Property('PRICE'))
146 147 Price = property(_GetPrice, 148 doc='''SMS price. Expressed using L{PricePrecision}. For a value expressed using L{PriceCurrency}, use L{PriceValue}. 149 150 @type: int 151 @see: L{PriceCurrency}, L{PricePrecision}, L{PriceToText}, L{PriceValue} 152 ''') 153
154 - def _GetPriceCurrency(self):
155 return self._Property('PRICE_CURRENCY')
156 157 PriceCurrency = property(_GetPriceCurrency, 158 doc='''SMS price currency. 159 160 @type: unicode 161 @see: L{Price}, L{PricePrecision}, L{PriceToText}, L{PriceValue} 162 ''') 163
164 - def _GetPricePrecision(self):
165 return int(self._Property('PRICE_PRECISION'))
166 167 PricePrecision = property(_GetPricePrecision, 168 doc='''SMS price precision. 169 170 @type: int 171 @see: L{Price}, L{PriceCurrency}, L{PriceToText}, L{PriceValue} 172 ''') 173
174 - def _GetPriceToText(self):
175 return (u'%s %.3f' % (self.PriceCurrency, self.PriceValue)).strip()
176 177 PriceToText = property(_GetPriceToText, 178 doc='''SMS price as properly formatted text with currency. 179 180 @type: unicode 181 @see: L{Price}, L{PriceCurrency}, L{PricePrecision}, L{PriceValue} 182 ''') 183
184 - def _GetPriceValue(self):
185 if self.Price < 0: 186 return 0.0 187 return float(self.Price) / (10 ** self.PricePrecision)
188 189 PriceValue = property(_GetPriceValue, 190 doc='''SMS price. Expressed in L{PriceCurrency}. 191 192 @type: float 193 @see: L{Price}, L{PriceCurrency}, L{PricePrecision}, L{PriceToText} 194 ''') 195
196 - def _GetReplyToNumber(self):
197 return self._Property('REPLY_TO_NUMBER')
198
199 - def _SetReplyToNumber(self, value):
200 self._Property('REPLY_TO_NUMBER', value)
201 202 ReplyToNumber = property(_GetReplyToNumber, _SetReplyToNumber, 203 doc='''Reply-to number for this SMS message. 204 205 @type: unicode 206 ''') 207
208 - def _SetSeen(self, value):
209 self._Property('SEEN', cndexp(value, 'TRUE', 'FALSE'))
210 211 Seen = property(fset=_SetSeen, 212 doc='''Read status of the SMS message. 213 214 @type: bool 215 ''') 216
217 - def _GetStatus(self):
218 return self._Property('STATUS')
219 220 Status = property(_GetStatus, 221 doc='''SMS message status. 222 223 @type: L{SMS message status<enums.smsMessageStatusUnknown>} 224 ''') 225
226 - def _GetTargetNumbers(self):
227 return tuple(esplit(self._Property('TARGET_NUMBERS'), ', '))
228
229 - def _SetTargetNumbers(self, value):
230 self._Property('TARGET_NUMBERS', ', '.join(value))
231 232 TargetNumbers = property(_GetTargetNumbers, _SetTargetNumbers, 233 doc='''Target phone numbers. 234 235 @type: tuple of unicode 236 ''') 237
238 - def _GetTargets(self):
239 return tuple([ISmsTarget((x, self)) for x in esplit(self._Property('TARGET_NUMBERS'), ', ')])
240 241 Targets = property(_GetTargets, 242 doc='''Target objects. 243 244 @type: tuple of L{ISmsTarget} 245 ''') 246
247 - def _GetTimestamp(self):
248 return float(self._Property('TIMESTAMP'))
249 250 Timestamp = property(_GetTimestamp, 251 doc='''Timestamp of this SMS message. 252 253 @type: float 254 @see: L{Datetime} 255 ''') 256
257 - def _GetType(self):
258 return self._Property('TYPE')
259 260 Type = property(_GetType, 261 doc='''SMS message type 262 263 @type: L{SMS message type<enums.smsMessageTypeUnknown>} 264 ''')
265 266
267 -class ISmsTarget(Cached):
268 '''Represents a single target of a multi-target SMS message. 269 ''' 270
271 - def __repr__(self):
272 return '<%s with Number=%s, Message=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Number), repr(self.Message))
273
274 - def _Init(self, Number_Message):
275 Number, Message = Number_Message 276 self._Number = Number 277 self._Message = Message
278
279 - def _GetMessage(self):
280 return self._Message
281 282 Message = property(_GetMessage, 283 doc='''An SMS message object this target refers to. 284 285 @type: L{ISmsMessage} 286 ''') 287
288 - def _GetNumber(self):
289 return self._Number
290 291 Number = property(_GetNumber, 292 doc='''Target phone number. 293 294 @type: unicode 295 ''') 296
297 - def _GetStatus(self):
298 for t in esplit(self._Message._Property('TARGET_STATUSES'), ', '): 299 number, status = t.split('=') 300 if number == self._Number: 301 return status
302 303 Status = property(_GetStatus, 304 doc='''Status of this target. 305 306 @type: L{SMS target status<enums.smsTargetStatusUnknown>} 307 ''')
308