pasturepy is a Python tool for generating JSON feed definitions for use with Graze. Use it to programmatically create and customize feeds for Graze.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add support for post type node

- update membership -> status

+66 -41
+3 -1
pasturepy/__init__.py
··· 4 4 from pasturepy.nodes.embed import EmbedNode 5 5 from pasturepy.nodes.ml import MLNode 6 6 from pasturepy.nodes.social import SocialNode 7 + from pasturepy import utils 7 8 8 9 __version__ = "0.1.0" 9 10 ··· 15 16 "EntityNode", 16 17 "EmbedNode", 17 18 "MLNode", 18 - "SocialNode" 19 + "SocialNode", 20 + "utils" 19 21 ]
+2 -2
pasturepy/constants/graze_json.py
··· 3 3 WORD_METHODS = {"regex_any", "regex_none"} 4 4 ENTITY_METHODS = {"entity_excludes", "entity_matches"} 5 5 COMPARISONS = {">=", "<=", ">", "<", "==", "!="} 6 - MEMBER_TYPES = {"in", "not_in"} 6 + STATUS_TYPES = {"in", "not_in"} 7 7 SOCIAL_LISTS = {"follows", "followers"} 8 - EMBED_COMPARISONS = {"==", "!="} 8 + EMBED_COMPARISONS = {"==", "!="}
+18
pasturepy/nodes/post.py
··· 1 + from pasturepy.constants.fields import POST_TYPES 2 + from pasturepy.constants.graze_json import STATUS_TYPES 3 + 4 + 5 + class PostNode: 6 + @staticmethod 7 + def post(filter_group, status: str, post_type: str): 8 + """Filter by entities (hashtags, mentions, domains, etc.).""" 9 + if status not in STATUS_TYPES: 10 + raise ValueError( 11 + f"Invalid method '{status}'. Must be one of {STATUS_TYPES}" 12 + ) 13 + if post_type not in POST_TYPES: 14 + raise ValueError( 15 + f"Invalid post_type '{post_type}'. Must be one of {POST_TYPES}" 16 + ) 17 + 18 + return filter_group.add_filter({status: [post_type]})
+28 -38
pasturepy/nodes/social.py
··· 1 - from pasturepy.constants.graze_json import MEMBER_TYPES, SOCIAL_LISTS 1 + from pasturepy.constants.graze_json import SOCIAL_LISTS, STATUS_TYPES 2 2 3 3 4 4 class SocialNode: 5 5 """Handles users, lists, social graph, and starter pack filtering.""" 6 - 6 + 7 7 @staticmethod 8 - def list_member(filter_group, list_uri: str, membership: str): 9 - if membership not in MEMBER_TYPES: 8 + def list_member(filter_group, list_uri: str, status: str): 9 + if status not in STATUS_TYPES: 10 10 raise ValueError( 11 - f"Invalid membership '{membership}'. " 12 - f"Must be one of: {', '.join(MEMBER_TYPES)}" 11 + f"Invalid status '{status}'. Must be one of: {', '.join(STATUS_TYPES)}" 13 12 ) 14 - 15 - return filter_group.add_filter({ 16 - "list_member": [list_uri, membership] 17 - }) 18 - 13 + 14 + return filter_group.add_filter({"list_member": [list_uri, status]}) 15 + 19 16 @staticmethod 20 - def starter_pack(filter_group, list_uri: str, membership: str): 21 - if membership not in MEMBER_TYPES: 17 + def starter_pack(filter_group, list_uri: str, status: str): 18 + if status not in STATUS_TYPES: 22 19 raise ValueError( 23 - f"Invalid membership '{membership}'. " 24 - f"Must be one of: {', '.join(MEMBER_TYPES)}" 20 + f"Invalid status '{status}'. Must be one of: {', '.join(STATUS_TYPES)}" 25 21 ) 26 - 27 - return filter_group.add_filter({ 28 - "starter_pack_member": [list_uri, membership] 29 - }) 30 - 22 + 23 + return filter_group.add_filter({"starter_pack_member": [list_uri, status]}) 24 + 31 25 @staticmethod 32 - def social_list(filter_group, user_did: list, membership: str): 33 - if membership not in MEMBER_TYPES: 26 + def social_list(filter_group, user_did: list, status: str): 27 + if status not in STATUS_TYPES: 34 28 raise ValueError( 35 - f"Invalid membership '{membership}'. " 36 - f"Must be one of: {', '.join(MEMBER_TYPES)}" 29 + f"Invalid status '{status}'. Must be one of: {', '.join(STATUS_TYPES)}" 37 30 ) 38 - 39 - return filter_group.add_filter({ 40 - "social_list": [user_did, membership] 41 - }) 42 - 31 + 32 + return filter_group.add_filter({"social_list": [user_did, status]}) 33 + 43 34 @staticmethod 44 - def social_graph(filter_group, user_handle: str, membership: str, list_type: str): 45 - if membership not in MEMBER_TYPES: 35 + def social_graph(filter_group, user_handle: str, status: str, list_type: str): 36 + if status not in STATUS_TYPES: 46 37 raise ValueError( 47 - f"Invalid membership '{membership}'. " 48 - f"Must be one of: {', '.join(MEMBER_TYPES)}" 38 + f"Invalid status '{status}'. Must be one of: {', '.join(STATUS_TYPES)}" 49 39 ) 50 - 40 + 51 41 if list_type not in SOCIAL_LISTS: 52 42 raise ValueError( 53 43 f"Invalid list_type '{list_type}'. " 54 44 f"Must be one of: {', '.join(SOCIAL_LISTS)}" 55 45 ) 56 - 57 - return filter_group.add_filter({ 58 - "social_graph": [user_handle, membership, list_type] 59 - }) 46 + 47 + return filter_group.add_filter( 48 + {"social_graph": [user_handle, status, list_type]} 49 + )
+15
pasturepy/utils/__init__.py
··· 1 + from .combine_regex import ( 2 + load_terms, 3 + normalize_escaping, 4 + deduplicate_terms, 5 + combine_terms_to_regex, 6 + load_and_combine, 7 + ) 8 + 9 + __all__ = [ 10 + "load_terms", 11 + "normalize_escaping", 12 + "deduplicate_terms", 13 + "combine_terms_to_regex", 14 + "load_and_combine", 15 + ]