From 1c4165468e41f5146f79f2575d04166b05d7bcf0 Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Thu, 22 Mar 2018 17:07:07 -0400 Subject: [PATCH] implemented burying feels --- ttbp/config/__init__.py | 2 +- ttbp/core.py | 27 +++++++++++++++++-- ttbp/ttbp.py | 58 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/ttbp/config/__init__.py b/ttbp/config/__init__.py index 9ab6561..fe81eca 100644 --- a/ttbp/config/__init__.py +++ b/ttbp/config/__init__.py @@ -72,7 +72,7 @@ GOPHER_PATH = os.path.join(USER_HOME, 'public_gopher', 'feels') USER_CONFIG = os.path.join(PATH, 'config') TTBPRC = os.path.join(USER_CONFIG, 'ttbprc') MAIN_FEELS = os.path.join(PATH, 'entries') -BURIED_FEELS = os.path.join(MAIN_FEELS, 'buried') +BURIED_FEELS = os.path.join(PATH, 'buried') NOPUB = os.path.join(USER_CONFIG, "nopub") BACKUPS = os.path.join(PATH, 'backups') diff --git a/ttbp/core.py b/ttbp/core.py index 98df199..d35db94 100644 --- a/ttbp/core.py +++ b/ttbp/core.py @@ -108,6 +108,7 @@ def load_files(feelsdir=config.MAIN_FEELS): load_nopubs() FILES = get_files(feelsdir) + if publishing(): write_html("index.html") if SETTINGS.get('gopher'): @@ -461,9 +462,30 @@ def toggle_nopub(filename): def bury_feel(filename): """buries given filename; this removes the feel from any publicly-readable - location, and moves the textfile to user's private feels directory""" + location, and moves the textfile to user's private feels directory. + + timestring will be added to the filename to disambiguate and prevent + filename collisions. + + creates buried feels dir if it doesn't exist. + + regenerates feels list and republishes.""" - pass + if not os.path.exists(config.BURIED_FEELS): + os.mkdir(config.BURIED_FEELS) + subprocess.call(["chmod", "700", config.BURIED_FEELS]) + + buryname = os.path.splitext(os.path.basename(filename))[0]+"-"+str(int(time.time()))+".txt" + + subprocess.call(["mv", os.path.join(config.MAIN_FEELS, filename), os.path.join(config.BURIED_FEELS, buryname)]) + subprocess.call(["chmod", "600", os.path.join(config.BURIED_FEELS, buryname)]) + + if publishing(): + unpublish_feel(filename) + + load_files() + + return os.path.join(config.BURIED_FEELS, buryname) def delete_feel(filename): """deletes given filename; removes the feel from publicly-readable @@ -472,6 +494,7 @@ def delete_feel(filename): feel = os.path.join(config.MAIN_FEELS, filename) if os.path.exists(feel): subprocess.call(["rm", feel]) + unpublish_feel(filename) load_files(config.MAIN_FEELS) def unpublish_feel(filename): diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 590af71..ad92cfb 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -1071,9 +1071,63 @@ def bury_feels(): """queries for a feel to bury, then calls the feels burying handler. """ - print(DUST) + feel = input("""\ +burying a feel removes it from view, including your own. buried feels are +stashed in a private directory at {buried_dir}; you can visit your feels there +from the command line, but no one else can view those files. + +(a buried feels browser is in the works; for now, you'll have to use the +command line to view your buried feels) + +which day's feels do you want to bury? + +YYYYMMDD (or 'q' to cancel)> """.format(buried_dir="")) + + if feel in util.BACKS: + return + + print("...") + time.sleep(0.1) + print("""\ +here's a preview of that feel. press when you're done reviewing! +-------------------------------------------------------------""") + + if subprocess.call(["less", os.path.join(config.MAIN_FEELS, feel+".txt")]): + redraw("burying feels") + print("""\ +sorry, i couldn't find feels for {date}! + +please try again, or type to cancel. +""".format(date=feel)) + return delete_feels() + + print(""" +------------------------------------------------------------- + +feels burying is irreversible! if you're sure you want to bury this feel, +type the date again to confirm, or 'q' to cancel. +""") + + confirm = input("[{feeldate}]> ".format(feeldate=feel)) + + if confirm == feel: + print("...") + time.sleep(0.5) + core.bury_feel(feel+".txt") + print("feels buried!") + else: + print("burying canceled!") + + ans = util.input_yn("""do you want to bury a different feel? please enter""") + + if ans: + redraw("burying feels") + return bury_feels() + else: + print("okay! please come back any time if you want to bury your feels!") + input("\n\npress to go back to managing your feels.\n\n") + redraw() - input("\n\npress to go back to managing your feels.\n\n") return def show_credits():