#105 Local and Shared following ( from a closed PR )

Open
opened 3 years ago by jyamihud · 1 comments

And issue is explained very well in a PR #103.

And issue is explained very well in a [PR #103](https://notabug.org/jyamihud/FastLBRY-terminal/pulls/103).

This could be resolved with a function to create new profiles (for the sake of example, say this is in flbry/following.py):

def create_profile(profile_name):
    # Minimum settings created for LBRY profile, based on LBRY Desktop
    empty_profile = "{\"value\": {\"subscriptions\": [], \"following\": []}}"
    check_output(lbrynet_binary["b"], "preference", "set", profile_name, empty_profile)
    
    center(f"Created new profile {profile_name}")

This prevents FastLBRY-terminal from crashing when trying to reference a non-existent shared profile. As an example implementation within following from flbry/following.py:

#...
def following():
    # Get the subscriptions
    following = check_output([lbrynet_binary["b"], "preference", "get"])
    try:
        following = json.loads(following)
    except:
        center("Connect to LBRY first.", "bdrd")
        return

    if "shared" not in following.keys():
        create_profile("shared")
        return # Alternatively, update following and continue

    following = following["shared"]["value"]["subscriptions"]
# ...

Adding support for additional profiles just involves adding a parameter to the following function to take on a profile name if supplied, otherwise default to shared:

#...
def following(profile="shared"):
    # Get the subscriptions
    following = check_output([lbrynet_binary["b"], "preference", "get"])
    try:
        following = json.loads(following)
    except:
        center("Connect to LBRY first.", "bdrd")
        return

    if profile not in following.keys():
        create_profile(profile)
        return # Alternatively, update following and continue

    following = following[profile]["value"]["subscriptions"]
# ...

with the appropriate lines in run.py, flbry/channel.py, and flbry/url.py being modified to use startswith over checking for equality:

#...
elif command.startswith("following") or command.startswith("subscriptions"):
    if " " in command:
        following.following(command[command.find(" ")+1:]
    else:
        following.following()
#...

Alternatively, a default profile could be set in the config file and later referenced in flbry/following.py:

#...
from flbry import settings

def following(profile=None):
    # Get the subscriptions
    following = check_output([lbrynet_binary["b"], "preference", "get"])
    try:
        following = json.loads(following)
    except:
        center("Connect to LBRY first.", "bdrd")
        return

    if not profile:
        profile = settings.get("default_profile")
        if not profile:
            center("No default profile is set", "bdrd")
            return # Alternatively, default to shared

    if profile not in following.keys():
        create_profile(profile)
        return # Alternatively, update following and continue

    following = following[profile]["value"]["subscriptions"]
# ...
This could be resolved with a function to create new profiles (for the sake of example, say this is in `flbry/following.py`): ``` def create_profile(profile_name): # Minimum settings created for LBRY profile, based on LBRY Desktop empty_profile = "{\"value\": {\"subscriptions\": [], \"following\": []}}" check_output(lbrynet_binary["b"], "preference", "set", profile_name, empty_profile) center(f"Created new profile {profile_name}") ``` This prevents FastLBRY-terminal from crashing when trying to reference a non-existent shared profile. As an example implementation within `following` from `flbry/following.py`: ``` #... def following(): # Get the subscriptions following = check_output([lbrynet_binary["b"], "preference", "get"]) try: following = json.loads(following) except: center("Connect to LBRY first.", "bdrd") return if "shared" not in following.keys(): create_profile("shared") return # Alternatively, update following and continue following = following["shared"]["value"]["subscriptions"] # ... ``` Adding support for additional profiles just involves adding a parameter to the `following` function to take on a profile name if supplied, otherwise default to shared: ``` #... def following(profile="shared"): # Get the subscriptions following = check_output([lbrynet_binary["b"], "preference", "get"]) try: following = json.loads(following) except: center("Connect to LBRY first.", "bdrd") return if profile not in following.keys(): create_profile(profile) return # Alternatively, update following and continue following = following[profile]["value"]["subscriptions"] # ... ``` with the appropriate lines in `run.py`, `flbry/channel.py`, and `flbry/url.py` being modified to use `startswith` over checking for equality: ``` #... elif command.startswith("following") or command.startswith("subscriptions"): if " " in command: following.following(command[command.find(" ")+1:] else: following.following() #... ``` Alternatively, a default profile could be set in the config file and later referenced in `flbry/following.py`: ``` #... from flbry import settings def following(profile=None): # Get the subscriptions following = check_output([lbrynet_binary["b"], "preference", "get"]) try: following = json.loads(following) except: center("Connect to LBRY first.", "bdrd") return if not profile: profile = settings.get("default_profile") if not profile: center("No default profile is set", "bdrd") return # Alternatively, default to shared if profile not in following.keys(): create_profile(profile) return # Alternatively, update following and continue following = following[profile]["value"]["subscriptions"] # ... ```
Sign in to join this conversation.
No Milestone
No assignee
2 Participants
Loading...
Cancel
Save
There is no content yet.