implemented burying feels

master
Vincent Zeng 2018-03-22 17:07:07 -04:00
parent 1789fb1ed4
commit 1c4165468e
3 changed files with 82 additions and 5 deletions

View File

@ -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')

View File

@ -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):

View File

@ -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 <q> 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 <q> 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 <enter> to go back to managing your feels.\n\n")
redraw()
input("\n\npress <enter> to go back to managing your feels.\n\n")
return
def show_credits():