Пример #1
0
    def get_dict_value_as_boolean( cls, dict_IN, name_IN, default_IN = False ):
    
        '''
        Accepts dictionary, name, and optional default value (if no default
           provided, default is -1).  If dictionary or name missing, returns
           default.  If name not present in dictionary, returns default.  If name
           in dictionary, returns whatever is mapped to name, converted to a decimal.Decimal instance
           through call to decimal.Decimal().
           
        Parameters:
        - dict_IN - dictionary we are looking in.
        - name_IN - name we are looking for in dictionary.
        - default_IN (defaults to -1) - default value to return if problem or not found in dict.
        
        Returns:
        - value_OUT - value mapped to name_IN in dict_IN, converted to int(), else the default value if problems or if not found in dict.
        '''
    
        # return reference
        value_OUT = None
        
        # first, get value.
        value_OUT = cls.get_dict_value( dict_IN, name_IN, default_IN )
        
        # convert to int unless value is None.
        if ( value_OUT != None ):

            # value is not None.
            value_OUT = BooleanHelper.convert_value_to_boolean( value_OUT )
            
        #-- END check to see if default was None --#
        
        return value_OUT
Пример #2
0
    def set_fields_from_reddiwrap( self, instance_IN, entetize_4_byte_unicode_IN = False, *args, **kwargs ):
    
        '''
        Accepts a reddiwrap UserInfo instance.  Uses it to populate this instance.
        '''
    
        # declare variables
        
        # got an instance passed in?
        if ( ( instance_IN ) and ( instance_IN != None ) ):
    
            self.reddit_id = instance_IN.id
            self.name = instance_IN.name                   # String, username
            self.is_gold = BooleanHelper.convert_value_to_boolean( instance_IN.is_gold ) # Boolean
            self.is_mod = BooleanHelper.convert_value_to_boolean( instance_IN.is_mod ) # Boolean
            self.created = instance_IN.created             # Time since 1/1/1970 when acct was created
            self.created_utc = instance_IN.created_utc     # Same as 'created', but in UTC
            self.link_karma = instance_IN.link_karma       # Integer, total score of submissions
            self.comment_karma = instance_IN.comment_karma # Integer, total score of comments

            # what to do about these?
            '''
Пример #3
0
    def set_fields_from_reddiwrap( self, instance_IN, entetize_4_byte_unicode_IN = False, *args, **kwargs ):
    
        '''
        Accepts a reddiwrap UserInfo instance.  Uses it to populate this instance.
        '''
    
        # declare variables
        
        # got an instance passed in?
        if ( ( instance_IN ) and ( instance_IN != None ) ):
    
            self.reddit_id = instance_IN.id
            self.name = instance_IN.name                   # String, username
            self.is_gold = BooleanHelper.convert_value_to_boolean( instance_IN.is_gold ) # Boolean
            self.is_mod = BooleanHelper.convert_value_to_boolean( instance_IN.is_mod ) # Boolean
            self.created = instance_IN.created             # Time since 1/1/1970 when acct was created
            self.created_utc = instance_IN.created_utc     # Same as 'created', but in UTC
            self.link_karma = instance_IN.link_karma       # Integer, total score of submissions
            self.comment_karma = instance_IN.comment_karma # Integer, total score of comments

            # what to do about these?
            '''
Пример #4
0
    def set_fields_from_reddiwrap( self, instance_IN, entetize_4_byte_unicode_IN = False, *args, **kwargs ):
    
        '''
        Accepts a reddiwrap Post instance.  Uses it to populate this instance.
        '''
    
        # declare variables
        text_value = ""
        
        # got an instance passed in?
        if ( ( instance_IN ) and ( instance_IN != None ) ):
    
            self.modhash = instance_IN.modhash             # base36 string for communicating with account
            self.reddit_id = instance_IN.id                # base36 id for a post (usually 5 characters)
            self.reddit_full_id = instance_IN.name                   # example: t1_czwe3. t# is content type, the rest is the ID
            self.name = instance_IN.name                   # example: t1_czwe3. t# is content type, the rest is the ID
            self.title = safe_string( instance_IN.title, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )  # Title of post
            self.url = safe_string( instance_IN.url, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN ) # URL to post
            self.author_name = instance_IN.author          # Username of author
            self.domain_name = safe_string( instance_IN.domain, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )              # Domain posted ot
            self.subreddit_name = instance_IN.subreddit         # Subreddit posted to
            self.subreddit_reddit_id = instance_IN.subreddit_id
            self.permalink = safe_string( instance_IN.permalink, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )         # Link to the post (including comments)
            self.is_self = BooleanHelper.convert_value_to_boolean( instance_IN.is_self ) # Self-post?
            self.selftext = safe_string( instance_IN.selftext, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )           # Self-post text
            self.selftext_html = safe_string( instance_IN.selftext_html, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN ) # HTML for self-post text
            self.num_comments = instance_IN.num_comments   # Number of comments
            self.score = instance_IN.score                 # upvotes - downvotes * crazy reddit vote fuzzing constant
            self.upvotes = instance_IN.upvotes
            self.downvotes = instance_IN.downvotes
            self.over_18 = BooleanHelper.convert_value_to_boolean( instance_IN.over_18 ) # NSFW post
            self.created = instance_IN.created
            self.created_dt = datetime.datetime.fromtimestamp( int( self.created ) )
            self.created_utc = instance_IN.created_utc
            self.created_utc_dt = datetime.datetime.fromtimestamp( int( self.created_utc ) )
            self.num_reports = instance_IN.num_reports
            self.banned_by = instance_IN.banned_by
            self.approved_by = instance_IN.approved_by
            self.link_flair_text = instance_IN.link_flair_text
            self.link_flair_class = instance_IN.link_flair_class # link_flair_css_class": null,
            self.author_flair_text = safe_string( instance_IN.author_flair_text, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )
            self.author_flair_class = instance_IN.author_flair_class
            self.clicked = BooleanHelper.convert_value_to_boolean( instance_IN.clicked ) # If logged-in user has clicked link yet
            self.hidden = BooleanHelper.convert_value_to_boolean( instance_IN.hidden )
            self.saved = BooleanHelper.convert_value_to_boolean( instance_IN.saved )
            self.edited = BooleanHelper.convert_value_to_boolean( instance_IN.edited )

            # what to do with these?
            '''
Пример #5
0
    def set_fields_from_reddiwrap( self, instance_IN, entetize_4_byte_unicode_IN = False, *args, **kwargs ):
    
        '''
        Accepts a reddiwrap Post instance.  Uses it to populate this instance.
        '''
    
        # declare variables
        text_value = ""
        
        # got an instance passed in?
        if ( ( instance_IN ) and ( instance_IN != None ) ):
    
            self.modhash = instance_IN.modhash             # base36 string for communicating with account
            self.reddit_id = instance_IN.id                # base36 id for a post (usually 5 characters)
            self.name = instance_IN.name                   # example: t1_czwe3. t# is content type, the rest is the ID
            self.title = safe_string( instance_IN.title, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )  # Title of post
            self.url = safe_string( instance_IN.url, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN ) # URL to post
            self.author_name = instance_IN.author          # Username of author
            self.domain = safe_string( instance_IN.domain, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )              # Domain posted ot
            self.subreddit_name = instance_IN.subreddit         # Subreddit posted to
            self.subreddit_reddit_id = instance_IN.subreddit_id
            self.permalink = safe_string( instance_IN.permalink, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )         # Link to the post (including comments)
            self.is_self = BooleanHelper.convert_value_to_boolean( instance_IN.is_self ) # Self-post?
            self.selftext = safe_string( instance_IN.selftext, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )           # Self-post text
            self.selftext_html = safe_string( instance_IN.selftext_html, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN ) # HTML for self-post text
            self.num_comments = instance_IN.num_comments   # Number of comments
            self.score = instance_IN.score                 # upvotes - downvotes * crazy reddit vote fuzzing constant
            self.upvotes = instance_IN.upvotes
            self.downvotes = instance_IN.downvotes
            self.over_18 = BooleanHelper.convert_value_to_boolean( instance_IN.over_18 ) # NSFW post
            self.created = instance_IN.created
            self.created_dt = datetime.datetime.fromtimestamp( int( self.created ) )
            self.created_utc = instance_IN.created_utc
            self.created_utc_dt = datetime.datetime.fromtimestamp( int( self.created_utc ) )
            self.num_reports = instance_IN.num_reports
            self.banned_by = instance_IN.banned_by
            self.approved_by = instance_IN.approved_by
            self.link_flair_text = instance_IN.link_flair_text
            self.link_flair_class = instance_IN.link_flair_class # link_flair_css_class": null,
            self.author_flair_text = safe_string( instance_IN.author_flair_text, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )
            self.author_flair_class = instance_IN.author_flair_class
            self.clicked = BooleanHelper.convert_value_to_boolean( instance_IN.clicked ) # If logged-in user has clicked link yet
            self.hidden = BooleanHelper.convert_value_to_boolean( instance_IN.hidden )
            self.saved = BooleanHelper.convert_value_to_boolean( instance_IN.saved )
            self.edited = BooleanHelper.convert_value_to_boolean( instance_IN.edited )

            # what to do with these?
            '''
Пример #6
0
 def set_fields_from_reddiwrap( self, instance_IN, entetize_4_byte_unicode_IN = False, *args, **kwargs ):
 
     '''
     Accepts a reddiwrap Comment instance.  Uses it to populate this instance.
     '''
 
     # declare variables
     
     # got an instance passed in?
     if ( ( instance_IN ) and ( instance_IN != None ) ):
 
         self.modhash = instance_IN.modhash
         self.reddit_id = instance_IN.id # reddit id (c9irgqx)
         self.reddit_full_id = instance_IN.name # type + reddit id (t1_c9irgqx)
         self.reddit_name = instance_IN.name # type + reddit id (t1_c9irgqx)
         self.link_id = instance_IN.link_id # type + reddit ID of parent post (t3_1cp0i3).
         self.parent_reddit_id = instance_IN.parent_id # reddit full ID of parent comment, if there is a parent.
         self.post_reddit_id = instance_IN.link_id # strip type?
         self.author_name = instance_IN.author # username of poster (UnixCurious)
         self.body = safe_string( instance_IN.body, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )
         self.body_html = safe_string( instance_IN.body_html, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )
         self.subreddit_name = instance_IN.subreddit # name of subreddit
         self.subreddit_reddit_id = instance_IN.subreddit_id # type + reddit ID of subreddit.
         self.upvotes = instance_IN.upvotes
         self.downvotes = instance_IN.downvotes
         self.score = instance_IN.score
         self.created = instance_IN.created
         self.created_dt = datetime.datetime.fromtimestamp( int( self.created ) )
         self.created_utc = instance_IN.created_utc
         self.created_utc_dt = datetime.datetime.fromtimestamp( int( self.created_utc ) )
         self.edited = BooleanHelper.convert_value_to_boolean( instance_IN.edited )
         self.num_reports = instance_IN.num_reports
         self.banned_by = instance_IN.banned_by
         self.approved_by = instance_IN.approved_by
         self.flair_class = instance_IN.flair_class
         self.flair_text = safe_string( instance_IN.flair_text, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )
         self.has_more_comments = instance_IN.has_more_comments
         self.more_comments_details = instance_IN.more_comments
Пример #7
0
 def set_fields_from_reddiwrap( self, instance_IN, entetize_4_byte_unicode_IN = False, *args, **kwargs ):
 
     '''
     Accepts a reddiwrap Comment instance.  Uses it to populate this instance.
     '''
 
     # declare variables
     
     # got an instance passed in?
     if ( ( instance_IN ) and ( instance_IN != None ) ):
 
         self.modhash = instance_IN.modhash
         self.reddit_id = instance_IN.id # reddit id (c9irgqx)
         self.reddit_full_id = instance_IN.name # type + reddit id (t1_c9irgqx)
         self.reddit_name = instance_IN.name # type + reddit id (t1_c9irgqx)
         self.link_id = instance_IN.link_id # type + reddit ID of parent post (t3_1cp0i3).
         self.parent_reddit_id = instance_IN.parent_id # reddit full ID of parent comment, if there is a parent.
         self.post_reddit_id = instance_IN.link_id # strip type?
         self.author_name = instance_IN.author # username of poster (UnixCurious)
         self.body = safe_string( instance_IN.body, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )
         self.body_html = safe_string( instance_IN.body_html, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )
         self.subreddit_name = instance_IN.subreddit # name of subreddit
         self.subreddit_reddit_id = instance_IN.subreddit_id # type + reddit ID of subreddit.
         self.upvotes = instance_IN.upvotes
         self.downvotes = instance_IN.downvotes
         self.score = instance_IN.score
         self.created = instance_IN.created
         self.created_dt = datetime.datetime.fromtimestamp( int( self.created ) )
         self.created_utc = instance_IN.created_utc
         self.created_utc_dt = datetime.datetime.fromtimestamp( int( self.created_utc ) )
         self.edited = BooleanHelper.convert_value_to_boolean( instance_IN.edited )
         self.num_reports = instance_IN.num_reports
         self.banned_by = instance_IN.banned_by
         self.approved_by = instance_IN.approved_by
         self.flair_class = instance_IN.flair_class
         self.flair_text = safe_string( instance_IN.flair_text, entetize_4_byte_unicode_IN = entetize_4_byte_unicode_IN )