From fecb5b9907d2c48a27b34dbce10cdbd2bd5a70c3 Mon Sep 17 00:00:00 2001 From: endorphant Date: Sun, 15 May 2016 18:15:53 -0400 Subject: [PATCH] working on private blogging first, breaking out all the setup optiosn into smaller functions for better readability. adding an option to set blog to be published or not, and checks this before printing public feels list. --- bin/_ttbp.py | 169 ++++++++++++++++++++++++++++++++++-------- bin/config/banner.txt | 2 +- bin/core.py | 3 +- bin/ttbp.py | 36 ++++++++- changelog.txt | 2 +- 5 files changed, 176 insertions(+), 36 deletions(-) diff --git a/bin/_ttbp.py b/bin/_ttbp.py index 5354fdd..8518ec5 100644 --- a/bin/_ttbp.py +++ b/bin/_ttbp.py @@ -189,42 +189,56 @@ def setup(): global SETTINGS # editor selection - print_menu(EDITORS) - choice = raw_input("\npick your favorite text editor: ") - while choice not in ['0', '1', '2', '3', '4']: - choice = raw_input("\nplease pick a number from the list: ") - - SETTINGS["editor"] = EDITORS[int(choice)] + SETTINGS.update({"editor": select_editor()}) redraw("text editor set to: "+SETTINGS["editor"]) + # set up public publish option + #publish = input_yn("""\ +#do you want to publish your feels online? + +#if yes, i'll make a directory in your public_html where your blog posts +#will be published. if not, your posts will only be readable from +#within the tilde.town network. + +#you can change this option any time. + +#please enter\ +#""") + SETTINGS.update({"publishing":select_publishing()}) + redraw("blog publishing: "+str(publishing())) + # publish directory selection - if SETTINGS["publish dir"]: - print("\tcurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])+"\n\n") - choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ") - if not choice: - choice = "blog" + #if SETTINGS["publish dir"]: + # print("\tcurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])+"\n\n") + #choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ") + #if not choice: + # choice = "blog" - publishing = os.path.join(PUBLIC, choice) - while os.path.exists(publishing): - second = raw_input("\n"+publishing+" already exists!\nif you're sure you want to use it, hit to confirm. otherwise, pick another location: ") - if second == "": - break - choice = second - publishing = os.path.join(PUBLIC, choice) + #publishing = os.path.join(PUBLIC, choice) + #while os.path.exists(publishing): + # second = raw_input("\n"+publishing+" already exists!\nif you're sure you want to use it, hit to confirm. otherwise, pick another location: ") + # if second == "": + # break + # choice = second + # publishing = os.path.join(PUBLIC, choice) - SETTINGS["publish dir"] = choice + #SETTINGS.update({"publish dir": choice}) + if publishing(): + SETTINGS.update({"publish dir": select_publish_dir()}) # set up publish directory - if not os.path.exists(publishing): - subprocess.call(["mkdir", publishing]) - subprocess.call(["touch", os.path.join(publishing, "index.html")]) - index = open(os.path.join(publishing, "index.html"), "w") - index.write("

ttbp blog placeholder

") - index.close() - if os.path.exists(WWW): - subprocess.call(["rm", WWW]) - subprocess.call(["ln", "-s", publishing, WWW]) - print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/\n\n") + #publishing = os.path.join(PUBLIC, SETTINGS.get("publish dir")) + #if not os.path.exists(publishing): + # subprocess.call(["mkdir", publishing]) + # subprocess.call(["touch", os.path.join(publishing, "index.html")]) + # index = open(os.path.join(publishing, "index.html"), "w") + # index.write("

ttbp blog placeholder

") + # index.close() + #if os.path.exists(WWW): + # subprocess.call(["rm", WWW]) + #subprocess.call(["ln", "-s", publishing, WWW]) + #print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS.get("publish dir")+"/\n\n") + make_publish_dir() # save settings ttbprc = open(TTBPRC, "w") @@ -283,8 +297,9 @@ def main_menu(): redraw("now viewing most recent entries\n\n") view_feed() elif choice == '4': - pretty_settings = "\n\ttext editor:\t" +SETTINGS["editor"] - pretty_settings += "\n\tpublish dir:\t" +os.path.join(PUBLIC, SETTINGS["publish dir"]) + pretty_settings = "\n\ttext editor:\t" +SETTINGS.get("editor") + pretty_settings += "\n\tpublish dir:\t" +os.path.join(PUBLIC, SETTINGS.get("publish dir")) + pretty_settings += "\n\tpubishing:\t"+str(SETTINGS.get("publishing")) redraw("now changing your settings. press if you didn't mean to do this.\n\ncurrent settings "+pretty_settings+"\n") try: @@ -336,7 +351,7 @@ def view_neighbors(users): for user in users: userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc"))) - url = LIVE+user+"/"+userRC["publish dir"] + url = LIVE+user+"/"+userRC.get("publish dir") count = 0 lastfile = "" files = os.listdir(os.path.join("/home", user, ".ttbp", "entries")) @@ -538,8 +553,13 @@ def www_neighbors(users): userList = [] for user in users: + if not publishing(user): + continue + userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc"))) + url = LIVE+user+"/"+userRC["publish dir"] + lastfile = "" files = os.listdir(os.path.join("/home", user, ".ttbp", "entries")) files.sort() @@ -590,6 +610,91 @@ def list_select(options, prompt): return ans +def input_yn(query): + # returns boolean True or False + + ans = raw_input(query+" [y/n] ") + + while ans not in ["y", "n"]: + ans = raw_input("'y' or 'n' please: ") + + if ans == "y": + return True + else: + return False + +def publishing(username = USER): + # checks .ttbprc for whether or not user wants their blog published online + + ttbprc = {} + + if username == USER: + ttbprc = SETTINGS + + else: + ttbprc = json.load(open(os.path.join("/home", username, ".ttbp", "config", "ttbprc"))) + + return ttbprc.get("publishing") + +def select_editor(): + # setup helper for editor selection + + print_menu(EDITORS) + choice = raw_input("\npick your favorite text editor: ") + while choice not in ['0', '1', '2', '3', '4']: + choice = raw_input("\nplease pick a number from the list: ") + + return EDITORS[int(choice)] + +def select_publish_dir(): + # setup helper for publish directory selection + + if SETTINGS["publish dir"]: + print("\tcurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])+"\n\n") + choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ") + if not choice: + choice = "blog" + + publishing = os.path.join(PUBLIC, choice) + while os.path.exists(publishing): + second = raw_input("\n"+publishing+" already exists!\nif you're sure you want to use it, hit to confirm. otherwise, pick another location: ") + if second == "": + break + choice = second + publishing = os.path.join(PUBLIC, choice) + + return choice + +def select_publishing(): + # setup helper for toggling publishing + + return input_yn("""\ +do you want to publish your feels online? + +if yes, i'll make a directory in your public_html where your blog posts +will be published. if not, your posts will only be readable from +within the tilde.town network. + +you can change this option any time. + +please enter\ +""") + +def make_publish_dir(): + # setup helper to create publishing directory + + publishing = os.path.join(PUBLIC, SETTINGS.get("publish dir")) + if not os.path.exists(publishing): + subprocess.call(["mkdir", publishing]) + subprocess.call(["touch", os.path.join(publishing, "index.html")]) + index = open(os.path.join(publishing, "index.html"), "w") + index.write("

ttbp blog placeholder

") + index.close() + if os.path.exists(WWW): + subprocess.call(["rm", WWW]) + subprocess.call(["ln", "-s", publishing, WWW]) + print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS.get("publish dir")+"/\n\n") + ##### start() diff --git a/bin/config/banner.txt b/bin/config/banner.txt index b2e142c..617a572 100644 --- a/bin/config/banner.txt +++ b/bin/config/banner.txt @@ -5,6 +5,6 @@ | |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | | | -| ver 0.8.0 (almost stable) | +| ver 0.8.5 (almost stable) | | ~endorphant/projects/ttbp/changelog.txt | |__________________________________________________________| diff --git a/bin/core.py b/bin/core.py index 04997c3..d85a239 100644 --- a/bin/core.py +++ b/bin/core.py @@ -187,7 +187,7 @@ def write_global_feed(blogList): - tilde.town global feels engine + tilde.town feels engine @@ -202,6 +202,7 @@ def write_global_feed(blogList):

 

live feels-sharing:

+

(time not exactly to scale)

    """) diff --git a/bin/ttbp.py b/bin/ttbp.py index 046eee9..1c4d4a6 100644 --- a/bin/ttbp.py +++ b/bin/ttbp.py @@ -270,6 +270,7 @@ def main_menu(): redraw() today = time.strftime("%Y%m%d") write_entry(os.path.join(DATA, today+".txt")) + www_neighbors(find_ttbps()) elif choice == '1': redraw("here are your recorded feels, listed by date:\n\n") view_own() @@ -340,7 +341,6 @@ def view_neighbors(users): files = os.listdir(os.path.join("/home", user, ".ttbp", "entries")) files.sort() for filename in files: - #if os.path.splitext(filename)[1] == ".txt" and len(os.path.splitext(filename)[0]) == 8: if core.valid(filename): count += 1 lastfile = os.path.join("/home", user, ".ttbp", "entries", filename) @@ -531,6 +531,40 @@ def find_ttbps(): return users +def www_neighbors(users): + # takes a raw list of valid users and formats for www view + + userList = [] + + for user in users: + userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc"))) + url = LIVE+user+"/"+userRC["publish dir"] + lastfile = "" + files = os.listdir(os.path.join("/home", user, ".ttbp", "entries")) + files.sort() + for filename in files: + if core.valid(filename): + lastfile = os.path.join("/home", user, ".ttbp", "entries", filename) + + ago = "never" + if lastfile: + last = os.path.getctime(lastfile) + since = time.time()-last + ago = util.pretty_time(int(since)) + " ago" + else: + last = 0 + + userList.append(["~"+user+" ("+ago+")", last]) + + # sort user by most recent entry + userList.sort(key = lambda userdata:userdata[1]) + userList.reverse() + sortedUsers = [] + for user in userList: + sortedUsers.append(user[0]) + + core.write_global_feed(sortedUsers) + def list_select(options, prompt): # runs the prompt for the list until a valid index is imputted diff --git a/changelog.txt b/changelog.txt index 7f9ab05..492a5a4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -23,10 +23,10 @@ CHANGELOG: ver 0.8.5 -publish feels directory to ~endorphant/ttbp/index.html + -(beta only) colorized menus ver 0.8.0 -markdown parsing for entries - -(beta only) colorized menus ver 0.7.5 -COLORFUL BANNER