-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
754 lines (709 loc) · 22.6 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
#
#Copyright (C) 2009 asylumfunk
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You may obtain a copy of this license at:
# http://www.gnu.org/licenses/gpl-3.0.html
"""Presentation layer"""
#Standard modules
import sys
import time
import urllib2
#Third-party modules
import twitter
import xbmc
import xbmcgui
#Project modules
import act
import auth
import crypt
from default import cfg
from default import i18n
class gui:
"""Handles the scripts user interface"""
"""
Description:
Default constructor
Initializes the UI language
Loads the user's credentials, if they are saved
"""
def __init__( self ):
username = cfg.get( "auth.username" )
password = cfg.get( "auth.password" )
password = crypt.de( password )
self.authentication = auth.Authentication()
self.player = player = xbmc.Player()
self.menuOptions_Main = [
i18n( "MainMenu_Options_UpdateManually" )
, i18n( "MainMenu_Options_ViewFriendsTimeline" )
, i18n( "menu.main.options.search" )
, i18n( "MainMenu_Options_Following" )
, i18n( "MainMenu_Options_Followers" )
, i18n( "menu.main.options.mentions" )
, i18n( "MainMenu_Options_DirectMessages" )
, i18n( "MainMenu_Options_EditAccount" )
, i18n( "MainMenu_Options_About" )
, i18n( "MainMenu_Options_Exit" )
]
self.menuOptions_DirectMessages = [
i18n( "Menu_DirectMessages_Compose" )
, i18n( "Menu_DirectMessages_Inbox" )
, i18n( "Menu_DirectMessages_Sent" )
]
self.DirectMessageType = {
"sent" : 1,
"received" : 2
}
self.UsersListType = {
"following" : 1,
"followers" : 2
}
self.version = sys.modules[ "__main__" ].__version__
self.ApplicationNameWithVersion = i18n( "ApplicationName" ) + ", v" + self.version
"""
Description:
Displays the "About" dialog
"""
def about( self ):
dialog = xbmcgui.Dialog()
dialog.ok( cfg.get( "about.tagLine" ), sys.modules[ "__main__" ].__author__, cfg.get( "about.url" ), cfg.get( "about.email" ) )
"""
Description:
Alerts the user that the Direct Message has been deleted
"""
def alertDirectMessageDeleted( self ):
dialog = xbmcgui.Dialog()
return dialog.ok( i18n( "Success" ), i18n( "Message_Alert_DirectMessage_Deleted" ) )
"""
Description:
Alerts the user that their message cannot be empty
"""
def alertMessageEmpty( self ):
dialog = xbmcgui.Dialog()
return dialog.ok( i18n( "Warning" ), i18n( "Message_Alert_Empty_Text" ) )
"""
Description:
Alerts the user that their message could not be sent
"""
def alertMessageNotSent( self ):
dialog = xbmcgui.Dialog()
return dialog.ok( i18n( "Warning" ), i18n( "Message_Alert_NotSent1" ), i18n( "Message_Alert_NotSent2" ), i18n( "Message_Alert_NotSent3" ) )
"""
Description:
Alerts the user that their message was successfully sent
"""
def alertMessageSuccessfullySent( self ):
dialog = xbmcgui.Dialog()
return dialog.ok( i18n( "Success" ), i18n( "Message_Alert_SentSuccessfully" ) )
"""
Description:
Alerts the user that their message cannot exceed the maximum length
"""
def alertMessageTooLong( self ):
dialog = xbmcgui.Dialog()
return dialog.ok( i18n( "Warning" ), i18n( "Message_Alert_TooLong_Text" ) %
{ "maxLength" : twitter.CHARACTER_LIMIT } )
"""
Description:
Alerts the user that Twitter.com could not be reached
"""
def alertServerConnectionFailed( self ):
dialog = xbmcgui.Dialog()
dialog.ok( i18n( "Warning" ), i18n( "Server_ConnectionFailed_Line1" ), i18n( "Server_ConnectionFailed_Line2" ), i18n( "Server_ConnectionFailed_Line3" ) )
"""
Description:
Alerts the user that their status cannot be empty
"""
def alertStatusEmpty( self ):
dialog = xbmcgui.Dialog()
dialog.ok( i18n( "Warning" ), i18n( "Tweet_Alert_Empty_Text" ) )
"""
Description:
Alerts the user that their status was successfully updated
"""
def alertStatusSuccessfullyUpdated( self ):
dialog = xbmcgui.Dialog()
dialog.ok( i18n( "Success" ), i18n( "Tweet_Alert_Success_Text" ) )
"""
Description:
Alerts the user that their status cannot exceed the maximum length
"""
def alertStatusTooLong( self ):
dialog = xbmcgui.Dialog()
dialog.ok( i18n( "Warning" ), i18n( "Tweet_Alert_TooLong_Text" ) %
{ "maxLength" : twitter.CHARACTER_LIMIT } )
"""
Description:
Alerts the user that the requested user timeline is protected
"""
def alertTimelineProtected( self, user ):
dialog = xbmcgui.Dialog()
dialog.ok( i18n( "UserTimeline_Protected_Header_Format" ) % { 'userName' : user.GetScreenName() },
i18n( "UserTimeline_Protected_Line1" ),
i18n( "UserTimeline_Protected_Line2" ) )
"""
Description:
Formats the display string for a direct message
Args:
message::twitter.DirectMessage - the message to be displayed
messageType::self.DirectMessageType - "sent" or "received"
Returns:
string - the properly formatted direct message string
"""
def formatDirectMessageDisplay( self, message, messageType ):
if messageType == self.DirectMessageType[ 'sent' ]:
userName = message.GetRecipientScreenName()
format = i18n( "DirectMessageDisplayFormat_Sent" )
else:
userName = message.GetSenderScreenName()
format = i18n( "DirectMessageDisplayFormat_Received" )
text = act.stripNewlines( message.GetText() )
created = time.localtime( message.GetCreatedAtInSeconds() )
timestamp = time.strftime( i18n( "TimestampFormat" ), created )
return format % locals()
"""
Description:
Prompts the user to update their status, mentioning a specified user
Args:
user::twitter.User - the user being mentioned
Returns:
Accept: boolean result flag
Cancel: None
"""
def mention( self, user ):
userName = user.GetScreenName()
message = self.promptMessage( i18n( "Tweet_EnterStatus" ), i18n( "Mention_Format" ) % locals() )
if message is None:
return None
else:
return self.tweet( message )
"""
Description:
Confirms if the user wants to delete the message.
If yes, the message is deleted.
Args:
message:twitter.DirectMessage - the message pending deletion
Returns:
Yes - True
No - False
"""
def promptDeleteMessage( self, message ):
dialog = xbmcgui.Dialog()
sure = dialog.yesno( i18n( "DirectMessage_DeletePrompt_Header" ),
i18n( "DirectMessage_DeletePrompt_Line1" ),
i18n( "DirectMessage_DeletePrompt_Line2" ) )
if sure:
self.authentication.api.DestroyDirectMessage( message.GetId() )
self.alertDirectMessageDeleted()
return sure
"""
Description:
Generic input prompt
Args:
headerText::string (not None) - the header text to be displayed with the prompt
defaultValue::string (not None) - the value used to prepopulate the prompt
maskInput::bool (not None) - whether or not input characters should be masked, eg: passwords
Returns:
string - if user input is non-empty
None - prompt is cancelled or input is empty
"""
def promptInput( headerText, defaultValue = "", maskInput = False ):
defaultValue = defaultValue or ""
keyboard = xbmc.Keyboard( defaultValue, headerText, maskInput )
keyboard.doModal()
if keyboard.isConfirmed():
input = keyboard.getText().strip()
if input:
return input
return None
promptInput = staticmethod( promptInput )
"""
Description:
Prompts the user to enter a screen name
Args:
title::string (optional) - title prompt to be displayed
default::string (optional) - default text to be pre-entered
acceptEmpty::bool (optional) - whether or not the prompt should loop if the user enters an empty entry
Returns:
Accept: the user's input (stripped of surrounding whitespace)
Cancel: None
"""
def promptScreenName( self, title = "", default = "", acceptEmpty = False ):
keyboard = xbmc.Keyboard( default, title )
while True:
keyboard.doModal()
if keyboard.isConfirmed():
name = keyboard.getText().strip()
if name != "" or acceptEmpty:
return name
else:
return None
"""
Description:
Prompts the user to enter a message
Alerts and loops if the message is too long
Args:
title::string (optional) - title prompt to be displayed
default::string (optional) - default text to be pre-entered
acceptEmpty::bool (optional) - whether or not the prompt should loop if the user enters an empty entry
Returns:
Accept: the user's input (stripped of surrounding whitespace)
Cancel: None
"""
def promptMessage( self, title = "", default = "", acceptEmpty = False ):
keyboard = xbmc.Keyboard( default, title )
while True:
keyboard.doModal()
if keyboard.isConfirmed():
message = keyboard.getText().strip()
if message == "":
if acceptEmpty:
return message
else:
self.alertMessageEmpty()
elif len( message ) > twitter.CHARACTER_LIMIT:
self.alertMessageTooLong()
else:
return message
else:
return None
"""
Description:
Prompts the user to reply to a status
Args:
originalStatus::twitter.Status - status to which the user is replying
Returns:
Success - True
Failure - False
Cancel - None
"""
def reply( self, originalStatus ):
screenName = originalStatus.GetUser().GetScreenName()
message = self.promptMessage( i18n( "Tweet_EnterStatus" ), "@" + screenName + " " )
if message is None:
return None
else:
return self.tweet( message )
"""
Description:
Allows the user to perform a search and view matching statuses
Args:
term::string - term to be searched for
"""
def search( self, term = None ):
if not term:
term = gui.promptInput( i18n( "search.input.heading" ) )
if term:
results = self.authentication.api.Search( term )
heading = i18n( "search.results.heading.format" ) % { "searchTerm" : term }
return self.viewTimeline( heading, results )
"""
Description:
Prompts the user for a screen name and message
Sends the message if both fields are completed
Returns:
Accept: True
Cancel: False
"""
def sendDirectMessage( self ):
screenName = ""
message = ""
while True:
screenName = self.promptScreenName( i18n( "DirectMessage_Send_EnterUsername" ), screenName )
if screenName is None:
return None
message = self.promptMessage( i18n( "DirectMessage_Send_EnterMessage" ) %
{ 'userName' : screenName } )
if message is not None:
break
try:
self.authentication.api.PostDirectMessage( screenName, message )
self.alertMessageSuccessfullySent()
return True
except:
self.alertMessageNotSent()
return False
"""
Description:
Prompts the user for a message
Sends the message if a non-empty message is entered
Args:
screenName::str - the recipient's screen name
Returns:
Accept: True
Cancel: False
"""
def sendDirectMessage( self, userName ):
message = self.promptMessage( i18n( "DirectMessage_Send_EnterMessage" ) % locals() )
if message is None:
return
try:
self.authentication.api.PostDirectMessage( userName, message )
self.alertMessageSuccessfullySent()
return True
except:
self.alertMessageNotSent()
return False
"""
Description:
Allows the user to perform a search and view matching statuses
Args:
term::string - term to be searched for
"""
def showMentions( self, username = None ):
if not username:
username = cfg.get( "auth.username" )
username = "@" + username
return self.search( username )
"""
Description:
Displays a menu with DirectMessage-related options
"""
def showMenu_DirectMessages( self ):
menu = xbmcgui.Dialog()
choice = 0
while choice >= 0:
options = self.menuOptions_DirectMessages
choice = menu.select( i18n( "Menu_DirectMessages_Title" ), options )
if choice >= 0:
action = self.menuOptions_DirectMessages[ choice ]
if action == i18n( "Menu_DirectMessages_Compose" ):
self.sendDirectMessage()
elif action == i18n( "Menu_DirectMessages_Inbox" ):
self.showMenu_DirectMessages_Inbox()
elif action == i18n( "Menu_DirectMessages_Sent" ):
self.showMenu_DirectMessages_Sent()
else:
break
"""
Description:
- Displays the user's Direct Message inbox
"""
def showMenu_DirectMessages_Inbox( self ):
self.showMenu_DirectMessages_List( self.DirectMessageType[ 'received' ] )
"""
Description:
- Displays a list of Direct Messages
Args:
messageType::self.DirectMessageType - "sent" or "received"
"""
def showMenu_DirectMessages_List( self, messageType ):
dialog = xbmcgui.Dialog()
choice = 0
while choice >= 0:
if messageType == self.DirectMessageType[ 'sent' ]:
messages = self.authentication.api.GetDirectMessagesSent()
header = i18n( "DirectMessageListHeader_Sent" )
else:
messages = self.authentication.api.GetDirectMessages()
header = i18n( "DirectMessageListHeader_Received" )
displayList = []
for message in messages:
display = self.formatDirectMessageDisplay( message, messageType )
displayList.append( display )
choice = dialog.select( header, displayList )
if choice < 0 or choice >= len( messages ):
break
else:
self.showMenu_DirectMessages_Selected( messages[ choice ], messageType )
"""
Description:
- Displays options that can be performed on a Direct Message
Args:
message::twitter.DirectMessage - currently selected message
messageType::self.DirectMessageType - "sent" or "received"
"""
def showMenu_DirectMessages_Selected( self, message, messageType ):
if messageType == self.DirectMessageType[ 'sent' ]:
replyTo = message.GetRecipientScreenName()
else:
replyTo = message.GetSenderScreenName()
options = [
i18n( "Menu_DirectMessages_Selected_Reply" ),
i18n( "Menu_DirectMessages_Selected_Delete" )
]
header = i18n( "Menu_DirectMessages_Selected_HeaderFormat" ) % \
{ "message" : self.formatDirectMessageDisplay( message, messageType ) }
dialog = xbmcgui.Dialog()
choice = 0
while choice >= 0:
choice = dialog.select( header, options )
if choice >= 0:
action = options[ choice ]
if action == i18n( "Menu_DirectMessages_Selected_Delete" ):
if self.promptDeleteMessage( message ):
break
elif action == i18n( "Menu_DirectMessages_Selected_Reply" ):
self.sendDirectMessage( replyTo )
"""
Description:
- Displays the user's Direct Message outbox
"""
def showMenu_DirectMessages_Sent( self ):
self.showMenu_DirectMessages_List( self.DirectMessageType[ 'sent' ] )
"""
Description:
Displays the script's main menu
Serves as the driver
"""
def showMenu_Main( self ):
menu = xbmcgui.Dialog()
choice = 0
audioIsPlaying = False
videoIsPlaying = False
mediaIsPlaying = False
while choice >= 0:
options = self.menuOptions_Main
audioIsPlaying = self.player.isPlayingAudio()
videoIsPlaying = self.player.isPlayingVideo()
if audioIsPlaying:
options.insert( 0, i18n( "MainMenu_Options_UpdateWithAudio" ) )
elif videoIsPlaying:
options.insert( 0, i18n( "MainMenu_Options_UpdateWithVideo" ) )
choice = menu.select( self.ApplicationNameWithVersion, options )
if choice >= 0:
action = options[ choice ]
try:
if action == i18n( "MainMenu_Options_UpdateWithAudio" ) or \
action == i18n( "MainMenu_Options_UpdateWithVideo" ):
self.tweetWhatImDoing()
elif action == i18n( "MainMenu_Options_UpdateManually" ):
self.tweetManually()
elif action == i18n( "MainMenu_Options_ViewFriendsTimeline" ):
self.viewFriendsTimeline()
elif action == i18n( "MainMenu_Options_DirectMessages" ):
self.showMenu_DirectMessages()
elif action == i18n( "MainMenu_Options_EditAccount" ):
self.authentication.authenticate( editing = True )
elif action == i18n( "MainMenu_Options_About" ):
self.about()
elif action == i18n( "MainMenu_Options_Following" ):
self.showMenu_UsersList( self.UsersListType[ "following" ] )
elif action == i18n( "MainMenu_Options_Followers" ):
self.showMenu_UsersList( self.UsersListType[ "followers" ] )
elif action == i18n( "menu.main.options.search" ):
self.search()
elif action == i18n( "menu.main.options.mentions" ):
self.showMentions()
else:
break
except urllib2.URLError:
self.alertServerConnectionFailed()
if audioIsPlaying or videoIsPlaying:
options.pop( 0 )
"""
Description:
Shows a menu of user-specific options
Args:
user::twitter.User - the specified user
listType::self.UsersListType - signifies the type of user list (following/follower)
Returns:
None
"""
def showMenu_User( self, user, listType ):
userName = user.GetScreenName()
optionMention = i18n( "Menu_User_Mention" ) % locals()
optionTimeline = i18n( "Menu_User_ViewTimeline" ) % locals()
optionDirectMessage = i18n( "Menu_User_DirectMessage" )
optionFollowing = i18n( "MainMenu_Options_Following" )
optionFollowers = i18n( "MainMenu_Options_Followers" )
options = [
optionTimeline
, optionMention
, optionDirectMessage
, optionFollowing
, optionFollowers
]
dialog = xbmcgui.Dialog()
choice = 0
while choice >= 0:
choice = dialog.select( userName, options )
if choice >= 0:
if options[ choice ] == optionMention:
self.mention( user )
elif options[ choice ] == optionTimeline:
self.viewUserTimeline( user )
elif options[ choice ] == optionDirectMessage:
self.sendDirectMessage( user.GetScreenName() )
elif options[ choice ] == optionFollowing:
self.showMenu_UsersList( self.UsersListType[ "following" ], user.GetScreenName() )
elif options[ choice ] == optionFollowers:
self.showMenu_UsersList( self.UsersListType[ "followers" ], user.GetScreenName() )
def showMenu_UsersList( self, listType = None, userName = None ):
if not userName:
userName = cfg.get( "auth.username" )
dialog = xbmcgui.Dialog()
if listType == self.UsersListType[ "following" ]:
users = self.authentication.api.GetFriends( userName )
header = i18n( "Menu_User_Header_Following" ) % locals()
else:
users = self.authentication.api.GetFollowers( userName )
header = i18n( "Menu_User_Header_Followers" ) % locals()
displayList = []
for user in users:
displayList.append( user.GetScreenName() )
choice = 0
while choice >= 0:
choice = dialog.select( header, displayList )
if choice < 0 or choice >= len( users ):
break
else:
self.showMenu_User( users[ choice ], listType )
"""
Description:
On the first run, user is prompted for their credentials
Displays the main menu
"""
def start( self ):
if self.authentication.authenticate():
self.showMenu_Main()
else:
print "You must log in."
return
"""
Description:
Updates the status for the currently authenticated user
Args:
message::string : the message to be sent
Returns:
True
TODO:
actually check if the status was successfully updated
"""
def tweet( self, message ):
try:
self.authentication.api.PostUpdate( message )
self.alertStatusSuccessfullyUpdated()
return True
except:
self.alertServerConnectionFailed()
return False
#todo: actually confirm
"""
Description:
Prompts the user to enter a status update
Alerts user and continues to prompt if status is either too long or empty
Returns:
Accept: Boolean result flag
Cancel: False
"""
def tweetManually( self ):
keyboard = xbmc.Keyboard( "", i18n( "Tweet_EnterStatus" ) )
while True:
keyboard.doModal()
if keyboard.isConfirmed():
message = keyboard.getText().strip()
if message == "":
self.alertStatusEmpty()
elif len( message ) > twitter.CHARACTER_LIMIT:
self.alertStatusTooLong()
else:
return self.tweet( message )
else:
return False
"""
Description:
Automatically updates the user's status with the video/music they're currently playing
Silently returns if user isn't playing any media
Returns:
Boolean result flag
TODO:
disable this option if user isn't playing any media
"""
def tweetWhatImDoing( self ):
if self.player.isPlayingAudio():
return self.tweetWhatImListeningTo()
elif self.player.isPlayingVideo():
return self.tweetWhatImWatching()
else:
return False
"""
Description:
Updates the user's status with the music they're currently listening to
Returns:
Boolean result flag
"""
def tweetWhatImListeningTo( self ):
try:
song = self.player.getMusicInfoTag()
except:
return False
info = i18n( "TweetMusic_MessageFormat" ) % { "artist" : song.getArtist(), "title" : song.getTitle() }
message = act.appendFooterToStatus( info, twitter.CHARACTER_LIMIT, i18n( "Tweet_Automatic_Suffix" ) )
return self.tweet( message )
"""
Description:
Updates the user's status with the video they're currently watching
Returns:
Boolean result flag
"""
def tweetWhatImWatching( self ):
try:
video = self.player.getVideoInfoTag()
except:
return False
title = video.getTitle()
if title == "":
title = act.parseTitleFromFilename( self.player.getPlayingFile() )
info = i18n( "TweetVideo_MessageFormat" ).encode( "utf_8" ) % { "title" : title }
message = act.appendFooterToStatus( info, twitter.CHARACTER_LIMIT, i18n( "Tweet_Automatic_Suffix" ) )
return self.tweet( message )
"""
Description:
Displays the user's friends timeline
This is the default view on the Twitter.com home page.
"""
def viewFriendsTimeline( self ):
header = i18n( "FriendsTimeline_Header" )
statuses = self.authentication.api.GetFriendsTimeline()
self.viewTimeline( header, statuses )
"""
Description:
Displays a generic timeline of statuses
Args:
header::string - text to be used as the dialog's header
statuses::twitter.Status[] - statuses to be displayed
"""
def viewTimeline( self, header, statuses ):
displayList = []
for status in statuses:
userName = status.GetUser().GetScreenName()
text = act.stripNewlines( status.GetText() )
created = time.localtime( status.GetCreatedAtInSeconds() )
timestamp = time.strftime( i18n( "TimestampFormat" ), created )
displayList.append( i18n( "FriendsTimeline_StatusFormat" ) % locals() )
while True:
dialog = xbmcgui.Dialog()
choice = dialog.select( header, displayList )
if choice < 0 or choice >= len( statuses ):
break
else:
self.reply( statuses[ choice ] )
"""
Description:
Displays the specified user's timeline
Alerts the user if the timeline is protected.
Args:
user::twitter.User - the user in question
"""
def viewUserTimeline( self, user ):
userName = user.GetScreenName()
header = i18n( "UserTimeline_Header_Format" ) % locals()
try:
statuses = self.authentication.api.GetUserTimeline( user.GetScreenName() )
except urllib2.HTTPError, e:
if e.code == 401:
self.alertTimelineProtected( user )
else:
raise
else:
self.viewTimeline( header, statuses )