def write_entry(entry=os.path.join(DATA, "test.txt")): ''' main feels-recording handler ''' entered = raw_input(""" feels will be recorded for today, """+time.strftime("%d %B %Y")+""". if you've already started recording feels for this day, you can pick up where you left off. you can write your feels in plaintext, markdown, html, or a mixture of these. press <enter> to begin recording your feels in your chosen text editor. """) if entered: entryFile = open(entry, "a") entryFile.write("\n"+entered+"\n") entryFile.close() subprocess.call([SETTINGS.get("editor"), entry]) left = "" if core.publishing(): core.load_files() core.write("index.html") left = "posted to "+LIVE+USER+"/"+str(SETTINGS.get("publish dir"))+"/index.html\n\n>" redraw(left + " thanks for sharing your feels!") return
def view_feels(townie): ''' generates a list of all feels by given townie and displays in date order * calls list_entries() to select feel to read ''' filenames = [] showpub = False if townie == USER: entryDir = DATA owner = "your" if core.publishing(): showpub = True else: owner = "~"+townie+"'s" entryDir = os.path.join("/home", townie, ".ttbp", "entries") for entry in os.listdir(entryDir): filenames.append(os.path.join(entryDir, entry)) metas = core.meta(filenames) if len(filenames) > 0: entries = [] for entry in metas: pub = "" if core.nopub(entry[0]): pub = "(nopub)" entries.append(""+entry[4]+" ("+p.no("word", entry[2])+") "+"\t"+pub) return list_entries(metas, entries, owner+" recorded feels, listed by date: \n") else: redraw("no feels recorded by ~"+townie)
def valid_setup(): ''' Checks to see if user has a sane ttbp environment. ''' global SETTINGS if not os.path.isfile(TTBPRC): return False try: SETTINGS = json.load(open(TTBPRC)) except ValueError: return False if core.publishing(): if not SETTINGS.get("publish dir"): return False if not os.path.exists(WWW): return False if not os.path.exists(os.path.join(WWW, SETTINGS.get("pubish dir"))): return False return True
def setup(): ''' master setup function * editor selection * publishing toggle * publish/unpublish as needed * directory selection TODO: break this out better? ''' global SETTINGS print("\n\ttext editor:\t" + SETTINGS.get("editor")) if core.publishing(): print("\tpublish dir:\t" + os.path.join(PUBLIC, str(SETTINGS.get("publish dir")))) print("\tpubishing:\t" + str(SETTINGS.get("publishing")) + "\n") # editor selection SETTINGS.update({"editor": select_editor()}) redraw("text editor set to: " + SETTINGS["editor"]) # publishing selection SETTINGS.update({"publishing": select_publishing()}) core.reload_ttbprc(SETTINGS) update_publishing() redraw("blog publishing: " + str(core.publishing())) if core.publishing(): print("publish directory: ~" + USER + "/public_html/" + SETTINGS.get("publish dir")) # save settings ttbprc = open(TTBPRC, "w") ttbprc.write( json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',', ':'))) ttbprc.close() raw_input("\nyou're all good to go, " + chatter.say("friend") + "! hit <enter> to continue.\n\n") redraw() return SETTINGS
def setup(): ''' master setup function * editor selection * publishing toggle * publish/unpublish as needed * directory selection TODO: break this out better? ''' global SETTINGS print("\n\ttext editor:\t" +SETTINGS.get("editor")) if core.publishing(): print("\tpublish dir:\t" +os.path.join(PUBLIC, str(SETTINGS.get("publish dir")))) print("\tpubishing:\t"+str(SETTINGS.get("publishing"))+"\n") # editor selection SETTINGS.update({"editor": select_editor()}) redraw("text editor set to: "+SETTINGS["editor"]) # publishing selection SETTINGS.update({"publishing":select_publishing()}) core.reload_ttbprc(SETTINGS) update_publishing() redraw("blog publishing: "+str(core.publishing())) if core.publishing(): print("publish directory: ~"+USER+"/public_html/"+SETTINGS.get("publish dir")) # save settings ttbprc = open(TTBPRC, "w") ttbprc.write(json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',',':'))) ttbprc.close() raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit <enter> to continue.\n\n") redraw() return SETTINGS
def update_publishing(): ''' updates publishing directory if user is publishing. otherwise, wipe it. ''' global SETTINGS if core.publishing(): oldDir = SETTINGS.get("publish dir") newDir = select_publish_dir() SETTINGS.update({"publish dir": newDir}) if oldDir: subprocess.call(["rm", os.path.join(PUBLIC, oldDir)]) make_publish_dir(newDir) core.load_files() core.write("index.html") else: unpublish() SETTINGS.update({"publish dir": None}) core.load(SETTINGS)
def main_menu(): ''' main navigation menu ''' menuOptions = [ "record your feels", "review your feels", "check out your neighbors", "browse global feels", "scribble some graffiti\t(new!)", "change your settings", "send some feedback", "see credits", "read documentation"] print("you're at ttbp home. remember, you can always press <ctrl-c> to come back here.\n") util.print_menu(menuOptions, RAINBOW) try: choice = raw_input("\ntell me about your feels (or 'quit' to exit): ") except KeyboardInterrupt: redraw(EJECT) return main_menu() if choice == '0': redraw() today = time.strftime("%Y%m%d") write_entry(os.path.join(DATA, today+".txt")) core.www_neighbors() elif choice == '1': if core.publishing(): intro = "here are some options for reviewing your feels:" redraw(intro) review_menu(intro) core.load_files() core.write("index.html") else: redraw("your recorded feels, listed by date:") view_feels(USER) elif choice == '2': users = core.find_ttbps() redraw("the following "+p.no("user", len(users))+" "+p.plural("is", len(users))+" recording feels on ttbp:") view_neighbors(users) elif choice == '3': redraw("most recent global entries") view_feed() elif choice == '4': graffiti_handler() elif choice == '5': redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this.") try: core.load(setup()) # reload settings to core except KeyboardInterrupt(): redraw(EJECT) redraw() elif choice == '6': redraw("you're about to send mail to ~endorphant about ttbp") feedback_menu() elif choice == '7': redraw() show_credits() elif choice == '8': subprocess.call(["lynx", os.path.join(SOURCE, "..", "README.html")]) redraw() elif choice in QUITS: return stop() else: redraw(INVALID) return main_menu()
def update_version(): ''' updates user to current version ''' global SETTINGS versionFile = os.path.join(PATH, "version") print("ttbp had some updates!") print("\ngive me a second to update you to version " + __version__ + "...\n") time.sleep(1) print("...") time.sleep(2) userVersion = "" if not os.path.isfile(versionFile): # from 0.8.5 to 0.8.6: # change style.css location if core.publishing(): if os.path.isfile(os.path.join(WWW, "style.css")): subprocess.call(["mv", os.path.join(WWW, "style.css"), CONFIG]) # change www symlink if os.path.exists(WWW): subprocess.call(["rm", WWW]) subprocess.call(["mkdir", WWW]) subprocess.call([ "ln", "-s", os.path.join(CONFIG, "style.css"), os.path.join(WWW, "style.css") ]) publishDir = os.path.join(PUBLIC, SETTINGS.get("publish dir")) if os.path.exists(publishDir): subprocess.call(["rm", "-rf", publishDir]) subprocess.call([ "ln", "-s", WWW, os.path.join(PUBLIC, SETTINGS.get("publish dir")) ]) # repopulate html files core.load_files() core.write("index.html") # add publishing setting print("\nnew feature!\n") SETTINGS.update({"publishing": select_publishing()}) update_publishing() ttbprc = open(TTBPRC, "w") ttbprc.write( json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',', ':'))) ttbprc.close() else: # version at least 0.8.6 userVersion = open(versionFile, "r").read().rstrip() # from 0.8.6 if userVersion == "0.8.6": print("\nresetting your publishing settings...\n") SETTINGS.update({"publishing": select_publishing()}) update_publishing() ttbprc = open(TTBPRC, "w") ttbprc.write( json.dumps(SETTINGS, sort_keys=True, indent=2, separators=(',', ':'))) ttbprc.close() # increment user versionfile open(versionFile, "w").write(__version__) print(""" you're all good to go, """ + chatter.say("friend") + """! please contact ~endorphant if somehing strange happened to you during this update. """) # show patch notes #if userVersion != "0.9.0" and userVersion != "0.9.0b": if userVersion[0:5] < "0.9.0": # version 0.9.0 patch notes: print(""" ver. 0.9.0 features: * browsing other people's feels from neighbor view * documentation browser """) if userVersion[0:5] < "0.9.1": # version 0.9.1 patch notes print(""" ver 0.9.1 features: * graffiti wall """) if userVersion[0:5] < "0.9.2": # version 0.9.2 patch notes print(""" ver 0.9.2 features: * paginated entry view * improved entry listing performance so it should be less sluggish (for now) * expanded menu for viewing your own feels (further features to be implemented) """)