From 8cb4201c2078c6910cede18485ef213111dcebc6 Mon Sep 17 00:00:00 2001 From: asdf Date: Sat, 7 Dec 2019 12:42:41 +1100 Subject: [PATCH] Remove -p option, ensure appropriate menu flow from post_link --- linkulator | 13 ------------- posts.py | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/linkulator b/linkulator index 06f67cb..9f60f6f 100755 --- a/linkulator +++ b/linkulator @@ -88,7 +88,6 @@ def print_categories(): graceful_exit() elif view_cat == "p": posts.post_link() - return else: try: view_cat = categories[int(view_cat) - 1] @@ -297,18 +296,6 @@ def parse_command(): print_categories() elif args[0] in ["-h", "--help", "help"]: print(help_text) - elif args[0] in ["-p", "--post", "-p"] and len(sys.argv) > 2: - print_banner() - posts.post_link(args[1]) - parse_ignore_file() - build_menu() - print_categories() - elif args[0] in ["-p", "--post", "-p"]: - print_banner() - posts.post_link() - parse_ignore_file() - build_menu() - print_categories() else: print("Unknown command: {}".format(args[0])) diff --git a/posts.py b/posts.py index 6aa6fd8..7b22fdb 100644 --- a/posts.py +++ b/posts.py @@ -3,7 +3,6 @@ import getpass import os import readline -import sys import time import config @@ -44,18 +43,17 @@ def is_valid(entry: str) -> bool: def get_input(item: str, prefill) -> str: - """Get user input with the specified prompt, validate and return it or exit""" + """Get user input with the specified prompt, validate and return it, or break if invalid""" while True: i: str = rlinput(item + ": ", prefill) if i == "": - sys.exit(0) + raise ValueError("Empty values are not permitted") if is_valid(i): return i - print('Pipes, "|", are illegal characters in Linkulator. Please try again.') -def save_link(link) -> None: +def save_link(link): """Saves the specified link data to the user's data file""" if os.path.exists(config.USER.datafile): append_write = "a" # append if already exists @@ -75,15 +73,18 @@ def save_link(link) -> None: print("Link added!") -def post_link(prefill: str = "") -> None: - """High-level """ +def post_link(prefill: str = ""): + """Handles the link posting process""" print("Enter link information here. Leaving any field blank aborts post.") link = Link() - - link.url = get_input("URL", prefill) - link.category = get_input("Category", "") - link.title = get_input("Title", "") + try: + link.url = get_input("URL", prefill) + link.category = get_input("Category", "") + link.title = get_input("Title", "") + except ValueError: + print("Post not recorded") + return link.timestamp = str(time.time()) save_link(link)