Don't like ads? PRO users don't see any ads ;-)

implementation of status.py in Facebook.py

By: qflint on May 16th, 2012  |  syntax: None  |  size: 1.73 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class status:
  2.     #status( string, string, list-of-string, list-of-comment)
  3.     ## initialize whoLiked and comments as empty strings
  4.     def __init__(self, whoPosted, status, whoLiked, comments):
  5.         self.whoPosted = whoPosted
  6.         self.status = status
  7.         self.whoLiked = whoLiked
  8.         self.comments = comments
  9.  
  10. ### string! I need this....
  11.  
  12.     #_str_: --> string
  13.     def __str__(self):
  14.         theLikes = ''
  15.         theComments = ''
  16.         length = len(self.whoLiked)
  17.        
  18.         if length == 1:    
  19.             if self.whoLiked != []:
  20.                 theLikes = theLikes + self.whoLiked[0] + ' likes this.' + '\n'
  21.         elif length == 2:
  22.             if self.whoLiked != []:
  23.                 theLikes = theLikes + self.whoLiked[0] + ' and ' + self.whoLiked[1] + ' like this.' + '\n'          
  24.         elif length > 2:
  25.             for like in range(length-1):
  26.                 theLikes = theLikes + self.whoLiked[like] + ', '
  27.             theLikes = theLikes + 'and ' + self.whoLiked[-1] + ' like this.' + '\n'
  28.        
  29.         for aComment in self.getcomments():
  30.             theComments = theComments + str(aComment) + '\n'
  31.            
  32.         return ( self.whoPosted + ' ' + self.status + '\n'
  33.                  + theLikes
  34.                  + theComments)
  35.  
  36.  
  37. #### alright, so i want to use the __str__ below inside of my print line in the for loop
  38.  
  39.  
  40.     #viewstatus: --> status
  41.     def viewstatus(self):
  42.         if self.loggedIn.lstrip() != '':
  43.             listOfID = list(self.posts.keys())
  44.             listOfPosts = list(self.posts.values())
  45.             for aPost in range(len(listOfPosts)):
  46.                 print ( '(' + str(listOfID[aPost]) + ')' +
  47.                         str(listOfPosts[aPost]))