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

Source Code for Module Skype4Py.user

  1  '''Users and groups. 
  2  ''' 
  3   
  4  from utils import * 
  5  from enums import * 
  6   
  7   
8 -class IUser(Cached):
9 '''Represents a Skype user. 10 ''' 11
12 - def __repr__(self):
13 return '<%s with Handle=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Handle))
14
15 - def _Init(self, Handle, Skype):
16 self._Skype = Skype 17 self._Handle = unicode(Handle)
18
19 - def _Property(self, PropName, Set=None, Cache=True):
20 return self._Skype._Property('USER', self.Handle, PropName, Set, Cache)
21
22 - def SaveAvatarToFile(self, Filename, AvatarId=1):
23 '''Saves user avatar to a file. 24 25 @param Filename: Destination path. 26 @type Filename: unicode 27 @param AvatarId: Avatar Id. 28 @type AvatarId: int 29 ''' 30 s = 'USER %s AVATAR %s %s' % (self.Handle, AvatarId, Filename) 31 self._Skype._DoCommand('GET %s' % s, s)
32
33 - def SetBuddyStatusPendingAuthorization(self, Text=''):
34 '''Sets the BuddyStaus property to L{budPendingAuthorization<enums.budPendingAuthorization>} 35 additionaly specifying the authorization text. 36 37 @param Text: The authorization text. 38 @type Text: unicode 39 @see: L{BuddyStatus} 40 ''' 41 self._Property('BUDDYSTATUS', '%d %s' % (budPendingAuthorization, Text), Cache=False)
42
43 - def _GetAbout(self):
44 return self._Property('ABOUT')
45 46 About = property(_GetAbout, 47 doc='''About text of the user. 48 49 @type: unicode 50 ''') 51
52 - def _GetAliases(self):
53 return tuple(esplit(self._Property('ALIASES')))
54 55 Aliases = property(_GetAliases, 56 doc='''Aliases of the user. 57 58 @type: tuple of unicode 59 ''') 60
61 - def _GetBirthday(self):
62 value = self._Property('BIRTHDAY') 63 if len(value) == 8: 64 from datetime import date 65 from time import strptime 66 return date(*strptime(value, '%Y%m%d')[:3])
67 68 Birthday = property(_GetBirthday, 69 doc='''Birthday of the user. 70 71 @type: datetime.date 72 ''') 73
74 - def _GetBuddyStatus(self):
75 return int(self._Property('BUDDYSTATUS'))
76
77 - def _SetBuddyStatus(self, value):
78 self._Property('BUDDYSTATUS', int(value), Cache=False)
79 80 BuddyStatus = property(_GetBuddyStatus, _SetBuddyStatus, 81 doc='''Buddy status of the user. 82 83 @type: L{Buddy status<enums.budUnknown>} 84 ''') 85
86 - def _GetCanLeaveVoicemail(self):
87 return self._Property('CAN_LEAVE_VM') == 'TRUE'
88 89 CanLeaveVoicemail = property(_GetCanLeaveVoicemail, 90 doc='''Tells if it is possible to send voicemail to the user. 91 92 @type: bool 93 ''') 94
95 - def _GetCity(self):
96 return self._Property('CITY')
97 98 City = property(_GetCity, 99 doc='''City of the user. 100 101 @type: unicode 102 ''') 103
104 - def _GetCountry(self):
105 value = self._Property('COUNTRY') 106 if value: 107 if self._Skype.Protocol >= 4: 108 value = chop(value)[-1] 109 return value
110 111 Country = property(_GetCountry, 112 doc='''Country of the user. 113 114 @type: unicode 115 ''') 116
117 - def _GetCountryCode(self):
118 if self._Skype.Protocol < 4: 119 return u'' 120 value = self._Property('COUNTRY') 121 if value: 122 value = chop(value)[0] 123 return value
124 125 CountryCode = property(_GetCountryCode, 126 doc='''ISO country code of the user. 127 128 @type: unicode 129 ''') 130
131 - def _GetDisplayName(self):
132 return self._Property('DISPLAYNAME')
133
134 - def _SetDisplayName(self, value):
135 self._Property('DISPLAYNAME', value)
136 137 DisplayName = property(_GetDisplayName, _SetDisplayName, 138 doc='''Display name of the user. 139 140 @type: unicode 141 ''') 142
143 - def _GetHandle(self):
144 return self._Handle
145 146 Handle = property(_GetHandle, 147 doc='''Skypename of the user. 148 149 @type: unicode 150 ''') 151
152 - def _GetFullName(self):
153 return self._Property('FULLNAME')
154 155 FullName = property(_GetFullName, 156 doc='''Full name of the user. 157 158 @type: unicode 159 ''') 160
161 - def _GetHasCallEquipment(self):
162 return self._Property('HASCALLEQUIPMENT') == 'TRUE'
163 164 HasCallEquipment = property(_GetHasCallEquipment, 165 doc='''Tells if the user has call equipment. 166 167 @type: bool 168 ''') 169
170 - def _GetHomepage(self):
171 return self._Property('HOMEPAGE')
172 173 Homepage = property(_GetHomepage, 174 doc='''Homepage URL of the user. 175 176 @type: unicode 177 ''') 178
179 - def _GetIsAuthorized(self):
180 return self._Property('ISAUTHORIZED') == 'TRUE'
181
182 - def _SetIsAuthorized(self, value):
183 self._Property('ISAUTHORIZED', cndexp(value, 'TRUE', 'FALSE'))
184 185 IsAuthorized = property(_GetIsAuthorized, _SetIsAuthorized, 186 doc='''Tells if the user is authorized to contact us. 187 188 @type: bool 189 ''') 190
191 - def _GetIsBlocked(self):
192 return self._Property('ISBLOCKED') == 'TRUE'
193
194 - def _SetIsBlocked(self, value):
195 self._Property('ISBLOCKED', cndexp(value, 'TRUE', 'FALSE'))
196 197 IsBlocked = property(_GetIsBlocked, _SetIsBlocked, 198 doc='''Tells whether this user is blocked or not. 199 200 @type: bool 201 ''') 202
203 - def _GetIsCallForwardActive(self):
204 return self._Property('IS_CF_ACTIVE') == 'TRUE'
205 206 IsCallForwardActive = property(_GetIsCallForwardActive, 207 doc='''Tells whether the user has Call Forwarding activated or not. 208 209 @type: bool 210 ''') 211
212 - def _GetIsSkypeOutContact(self):
213 return self.OnlineStatus == olsSkypeOut
214 215 IsSkypeOutContact = property(_GetIsSkypeOutContact, 216 doc='''Tells whether a user is a SkypeOut contact. 217 218 @type: bool 219 ''') 220
221 - def _GetIsVideoCapable(self):
222 return self._Property('IS_VIDEO_CAPABLE') == 'TRUE'
223 224 IsVideoCapable = property(_GetIsVideoCapable, 225 doc='''Tells if the user has video capability. 226 227 @type: bool 228 ''') 229
230 - def _GetIsVoicemailCapable(self):
231 return self._Property('IS_VOICEMAIL_CAPABLE') == 'TRUE'
232 233 IsVoicemailCapable = property(_GetIsVoicemailCapable, 234 doc='''Tells if the user has voicemail capability. 235 236 @type: bool 237 ''') 238
239 - def _GetLanguage(self):
240 value = self._Property('LANGUAGE') 241 if value: 242 if self._Skype.Protocol >= 4: 243 value = chop(value)[-1] 244 return value
245 246 Language = property(_GetLanguage, 247 doc='''The language of the user. 248 249 @type: unicode 250 ''') 251
252 - def _GetLanguageCode(self):
253 if self._Skype.Protocol < 4: 254 return u'' 255 value = self._Property('LANGUAGE') 256 if value: 257 value = chop(value)[0] 258 return value
259 260 LanguageCode = property(_GetLanguageCode, 261 doc='''The ISO language code of the user. 262 263 @type: unicode 264 ''') 265
266 - def _GetLastOnline(self):
267 return float(self._Property('LASTONLINETIMESTAMP'))
268 269 LastOnline = property(_GetLastOnline, 270 doc='''The time when a user was last online as a timestamp. 271 272 @type: float 273 @see: L{LastOnlineDatetime} 274 ''') 275
276 - def _GetLastOnlineDatetime(self):
277 from datetime import datetime 278 return datetime.fromtimestamp(self.LastOnline)
279 280 LastOnlineDatetime = property(_GetLastOnlineDatetime, 281 doc='''The time when a user was last online as a datetime. 282 283 @type: datetime.datetime 284 @see: L{LastOnline} 285 ''') 286
287 - def _GetMoodText(self):
288 return self._Property('MOOD_TEXT')
289 290 MoodText = property(_GetMoodText, 291 doc='''Mood text of the user. 292 293 @type: unicode 294 ''') 295
296 - def _GetNumberOfAuthBuddies(self):
297 return int(self._Property('NROF_AUTHED_BUDDIES'))
298 299 NumberOfAuthBuddies = property(_GetNumberOfAuthBuddies, 300 doc='''Number of authenticated buddies in user's contact list. 301 302 @type: int 303 ''') 304
305 - def _GetOnlineStatus(self):
306 return self._Property('ONLINESTATUS')
307 308 OnlineStatus = property(_GetOnlineStatus, 309 doc='''Online status of the user. 310 311 @type: L{Online status<enums.olsUnknown>} 312 ''') 313
314 - def _GetPhoneHome(self):
315 return self._Property('PHONE_HOME')
316 317 PhoneHome = property(_GetPhoneHome, 318 doc='''Home telephone number of the user. 319 320 @type: unicode 321 ''') 322
323 - def _GetPhoneMobile(self):
324 return self._Property('PHONE_MOBILE')
325 326 PhoneMobile = property(_GetPhoneMobile, 327 doc='''Mobile telephone number of the user. 328 329 @type: unicode 330 ''') 331
332 - def _GetPhoneOffice(self):
333 return self._Property('PHONE_OFFICE')
334 335 PhoneOffice = property(_GetPhoneOffice, 336 doc='''Office telephone number of the user. 337 338 @type: unicode 339 ''') 340
341 - def _GetProvince(self):
342 return self._Property('PROVINCE')
343 344 Province = property(_GetProvince, 345 doc='''Province of the user. 346 347 @type: unicode 348 ''') 349
350 - def _GetReceivedAuthRequest(self):
351 return self._Property('RECEIVEDAUTHREQUEST')
352 353 ReceivedAuthRequest = property(_GetReceivedAuthRequest, 354 doc='''Text message for authorization request. Available only when user asks for authorization. 355 356 @type: unicode 357 ''') 358
359 - def _GetRichMoodText(self):
360 return self._Property('RICH_MOOD_TEXT')
361 362 RichMoodText = property(_GetRichMoodText, 363 doc='''Advanced version of L{MoodText}. 364 365 @type: unicode 366 @see: U{https://developer.skype.com/Docs/ApiDoc/SET_PROFILE_RICH_MOOD_TEXT} 367 ''') 368
369 - def _GetSex(self):
370 return self._Property('SEX')
371 372 Sex = property(_GetSex, 373 doc='''Sex of the user. 374 375 @type: L{User sex<enums.usexUnknown>} 376 ''') 377
378 - def _GetSpeedDial(self):
379 return self._Property('SPEEDDIAL')
380
381 - def _SetSpeedDial(self, value):
382 self._Property('SPEEDDIAL', value)
383 384 SpeedDial = property(_GetSpeedDial, _SetSpeedDial, 385 doc='''Speed-dial code assigned to the user. 386 387 @type: unicode 388 ''') 389
390 - def _GetTimezone(self):
391 return int(self._Property('TIMEZONE'))
392 393 Timezone = property(_GetTimezone, 394 doc='''Timezone of the user in minutes from GMT. 395 396 @type: int 397 ''')
398 399
400 -class IGroup(Cached):
401 '''Represents a group of Skype users. 402 ''' 403
404 - def __repr__(self):
405 return '<%s with Id=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id))
406
407 - def _Alter(self, AlterName, Args=None):
408 return self._Skype._Alter('GROUP', self._Id, AlterName, Args)
409
410 - def _Init(self, Id, Skype):
411 self._Skype = Skype 412 self._Id = int(Id)
413
414 - def _Property(self, PropName, Value=None, Cache=True):
415 return self._Skype._Property('GROUP', self._Id, PropName, Value, Cache)
416
417 - def Accept(self):
418 '''Accepts an invitation to join a shared contact group. 419 ''' 420 self._Alter('ACCEPT')
421
422 - def AddUser(self, Username):
423 '''Adds new a user to the group. 424 425 @param Username: Skypename of the new user. 426 @type Username: unicode 427 ''' 428 self._Alter('ADDUSER', Username)
429
430 - def Decline(self):
431 '''Declines an invitation to join a shared contact group. 432 ''' 433 self._Alter('DECLINE')
434
435 - def RemoveUser(self, Username):
436 '''Removes a user from the group. 437 438 @param Username: Skypename of the user. 439 @type Username: unicode 440 ''' 441 self._Alter('REMOVEUSER', Username)
442
443 - def Share(self, MessageText=''):
444 '''Shares a contact group. 445 446 @param MessageText: Message text for group members. 447 @type MessageText: unicode 448 ''' 449 self._Alter('SHARE', MessageText)
450
451 - def _GetCustomGroupId(self):
452 return self._Property('CUSTOM_GROUP_ID')
453 454 CustomGroupId = property(_GetCustomGroupId, 455 doc='''Persistent group ID. The custom group ID is a persistent value that does not change. 456 457 @type: unicode 458 ''') 459
460 - def _GetDisplayName(self):
461 return self._Property('DISPLAYNAME')
462
463 - def _SetDisplayName(self, value):
464 self._Property('DISPLAYNAME', value)
465 466 DisplayName = property(_GetDisplayName, _SetDisplayName, 467 doc='''Display name of the group. 468 469 @type: unicode 470 ''') 471
472 - def _GetId(self):
473 return self._Id
474 475 Id = property(_GetId, 476 doc='''Group Id. 477 478 @type: int 479 ''') 480
481 - def _GetIsExpanded(self):
482 return self._Property('EXPANDED') == 'TRUE'
483 484 IsExpanded = property(_GetIsExpanded, 485 doc='''Tells if the group is expanded in the client. 486 487 @type: bool 488 ''') 489
490 - def _GetIsVisible(self):
491 return self._Property('VISIBLE') == 'TRUE'
492 493 IsVisible = property(_GetIsVisible, 494 doc='''Tells if the group is visible in the client. 495 496 @type: bool 497 ''') 498
499 - def _GetOnlineUsers(self):
500 return tuple([x for x in self.Users if x.OnlineStatus == olsOnline])
501 502 OnlineUsers = property(_GetOnlineUsers, 503 doc='''Users of the group that are online 504 505 @type: tuple of L{IUser} 506 ''') 507
508 - def _GetType(self):
509 return self._Property('TYPE')
510 511 Type = property(_GetType, 512 doc='''Group type. 513 514 @type: L{Group type<enums.grpUnknown>} 515 ''') 516
517 - def _GetUsers(self):
518 return tuple([IUser(x, self._Skype) for x in esplit(self._Property('USERS', Cache=False), ', ')])
519 520 Users = property(_GetUsers, 521 doc='''Users in this group. 522 523 @type: tuple of L{IUser} 524 ''')
525