mf2util.py
def classify_comment(parsed, target_urls):
    """Find and categorize comments that reference any of a collection of
    target URLs. Looks for references of type reply, like, and repost.

    :param dict parsed: a mf2py parsed dict
    :param list target_urls: a collection of urls that represent the
      target post. this can include alternate or shortened URLs.
    :return: a list of applicable comment types ['like', 'reply', 'repost']
    """
    def process_references(objs, reftypes, result):
        for obj in objs:
            if isinstance(obj, dict):
                if any(url in target_urls for url
                       in obj.get('properties', {}).get('url', [])):
                    result += (r for r in reftypes if r not in result)
            elif obj in target_urls:
                result += (r for r in reftypes if r not in result)

    result = []
    hentry = find_first_entry(parsed, ['h-entry'])
    if hentry:
        reply_type = []
        if 'rsvp' in hentry['properties']:
            reply_type.append('rsvp')
        if 'invitee' in hentry['properties']:
            reply_type.append('invite')
        reply_type.append('reply')

        # TODO handle rel=in-reply-to
        for prop in ('in-reply-to', 'reply-to', 'reply'):
            process_references(
                hentry['properties'].get(prop, []), reply_type, result)

        for prop in ('like-of', 'like'):
            process_references(
                hentry['properties'].get(prop, []), ('like',), result)

        for prop in ('repost-of', 'repost'):
            process_references(
                hentry['properties'].get(prop, []), ('repost',), result)

    return result
Find and categorize comments that reference any of a collection of
    target URLs. Looks for references of type reply, like, and repost.

    :param dict parsed: a mf2py parsed dict
    :param list target_urls: a collection of urls that represent the
      target post. this can include alternate or shortened URLs.
    :return: a list of applicable comment types ['like', 'reply', 'repost']
    
Find and categorize comments that reference any of a collection of
target URLs. Looks for references of type reply, like, and repost.
Find and categorize comments that reference any of a collection of target URLs . Looks for references of type reply like and repost .
def classify_comment(parsed, target_urls):
    def process_references(objs, reftypes, result):
        for obj in objs:
            if isinstance(obj, dict):
                if any(url in target_urls for url
                       in obj.get('properties', {}).get('url', [])):
                    result += (r for r in reftypes if r not in result)
            elif obj in target_urls:
                result += (r for r in reftypes if r not in result)
    result = []
    hentry = find_first_entry(parsed, ['h-entry'])
    if hentry:
        reply_type = []
        if 'rsvp' in hentry['properties']:
            reply_type.append('rsvp')
        if 'invitee' in hentry['properties']:
            reply_type.append('invite')
        reply_type.append('reply')
        for prop in ('in-reply-to', 'reply-to', 'reply'):
            process_references(
                hentry['properties'].get(prop, []), reply_type, result)
        for prop in ('like-of', 'like'):
            process_references(
                hentry['properties'].get(prop, []), ('like',), result)
        for prop in ('repost-of', 'repost'):
            process_references(
                hentry['properties'].get(prop, []), ('repost',), result)
    return result
def classify_comment ( parsed , target_urls ) : def process_references ( objs , reftypes , result ) : for obj in objs : if isinstance ( obj , dict ) : if any ( url in target_urls for url in obj . get ( 'properties' , { } ) . get ( 'url' , [ ] ) ) : result += ( r for r in reftypes if r not in result ) elif obj in target_urls : result += ( r for r in reftypes if r not in result ) result = [ ] hentry = find_first_entry ( parsed , [ 'h-entry' ] ) if hentry : reply_type = [ ] if 'rsvp' in hentry [ 'properties' ] : reply_type . append ( 'rsvp' ) if 'invitee' in hentry [ 'properties' ] : reply_type . append ( 'invite' ) reply_type . append ( 'reply' ) for prop in ( 'in-reply-to' , 'reply-to' , 'reply' ) : process_references ( hentry [ 'properties' ] . get ( prop , [ ] ) , reply_type , result ) for prop in ( 'like-of' , 'like' ) : process_references ( hentry [ 'properties' ] . get ( prop , [ ] ) , ( 'like' , ) , result ) for prop in ( 'repost-of' , 'repost' ) : process_references ( hentry [ 'properties' ] . get ( prop , [ ] ) , ( 'repost' , ) , result ) return result
Find and categorize comments that reference any of a collection of
target URLs.
Find and categorize comments that reference any of a collection of target URLs .
"""Find and categorize comments that reference any of a collection of
    target URLs. Looks for references of type reply, like, and repost.

    :param dict parsed: a mf2py parsed dict
    :param list target_urls: a collection of urls that represent the
      target post. this can include alternate or shortened URLs.
    :return: a list of applicable comment types ['like', 'reply', 'repost']
    """ # TODO handle rel=in-reply-to
a list of applicable comment types ['like', 'reply', 'repost']
a list of applicable comment types [ ' like ' ' reply ' ' repost ' ]
parsed
a mf2py parsed dict
a mf2py parsed dict
target_urls
a collection of urls that represent the
target post. this can include alternate or shortened URLs.
a collection of urls that represent the target post . this can include alternate or shortened URLs .