From c16662192ec46deff13d2ab3d145d70b8dae94b9 Mon Sep 17 00:00:00 2001 From: endorphant Date: Sun, 1 May 2016 19:34:20 -0400 Subject: [PATCH] setup and posting function running --- bin/config/banner.txt | 2 +- bin/config/{ => defaults}/footer.txt | 0 bin/config/{ => defaults}/header.txt | 4 +-- bin/config/{ => defaults}/style.css | 0 bin/core.py | 7 ++++- bin/ttbp.py | 47 ++++++++++++++++++++++------ bin/update.py | 1 + lib/lang.json | 12 +++---- 8 files changed, 54 insertions(+), 19 deletions(-) rename bin/config/{ => defaults}/footer.txt (100%) rename bin/config/{ => defaults}/header.txt (63%) rename bin/config/{ => defaults}/style.css (100%) diff --git a/bin/config/banner.txt b/bin/config/banner.txt index b40273a..a2c7930 100644 --- a/bin/config/banner.txt +++ b/bin/config/banner.txt @@ -2,4 +2,4 @@ | TILDE TOWN | | BLOGGING | | PLATFORM | -============== ver 0.1 (highly unstable) +============== ver 0.2 (highly unstable) diff --git a/bin/config/footer.txt b/bin/config/defaults/footer.txt similarity index 100% rename from bin/config/footer.txt rename to bin/config/defaults/footer.txt diff --git a/bin/config/header.txt b/bin/config/defaults/header.txt similarity index 63% rename from bin/config/header.txt rename to bin/config/defaults/header.txt index b3c64f5..e07e7fd 100644 --- a/bin/config/header.txt +++ b/bin/config/defaults/header.txt @@ -1,12 +1,12 @@ - ~endorphant + $USER on TTBP
-

~endorphant@tilde.town

+

~$USER@TTBP

diff --git a/bin/config/style.css b/bin/config/defaults/style.css similarity index 100% rename from bin/config/style.css rename to bin/config/defaults/style.css diff --git a/bin/core.py b/bin/core.py index 6642796..95ded68 100644 --- a/bin/core.py +++ b/bin/core.py @@ -32,13 +32,18 @@ MONTHS = { } def load(): - global FILES global HEADER global FOOTER HEADER = open(os.path.join(CONFIG, "header.txt")).read() FOOTER = open(os.path.join(CONFIG, "footer.txt")).read() + load_files() + +def load_files(): + global FILES + + FILES = [] for file in os.listdir(DATA): filename = os.path.join(DATA, file) if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt": diff --git a/bin/ttbp.py b/bin/ttbp.py index 067b80e..0743a93 100644 --- a/bin/ttbp.py +++ b/bin/ttbp.py @@ -7,13 +7,14 @@ import subprocess import time import json -#import core +import core import chatter ## system globals SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") LIVE = "http://tilde.town/~" FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail") +USERFILE = os.path.join("/home", "endorphant", "projects", "ttbp", "users.txt") ## user globals USER = os.path.basename(os.path.expanduser("~")) @@ -51,7 +52,7 @@ def start(): redraw() #print(chatter.say("greet")+", "+chatter.say("friend")) #print("(remember, you can always press ctrl-c to come home)\n") - print("if you don't want to be here at any point, press ctrl-d and it'll all go away.\njust keep in mind that you might lose anything you've started here.\n") + print("if you don't want to be here at any point, press and it'll all go away.\njust keep in mind that you might lose anything you've started here.\n") print(check_init()) try: @@ -69,8 +70,9 @@ def stop(): def check_init(): global SETTINGS + print("\n\n") if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")): - print("welcome back, "+USER+".") + print(chatter.say("greet")+", "+USER+".") while not os.path.isfile(TTBPRC): setup_handler() try: @@ -78,13 +80,31 @@ def check_init(): except ValueError: setup_handler() - raw_input("\n\npress enter to explore your feelings.\n\n") + raw_input("\n\npress to explore your feelings.\n\n") + core.load() return "" else: return init() def init(): - raw_input("i don't recognize you, stranger. let's make friends someday.\n\npress enter to explore some options.\n\n") + try: + raw_input("i don't recognize you, stranger. let's make friends.\n\npress to begin, or to get out of here. \n\n") + except KeyboardInterrupt: + print("\n\nthanks for checking in! i'll always be here.\n\n") + quit() + + users = open(USERFILE, 'a') + users.write(USER+"\n") + users.close() + subprocess.call(["mkdir", PATH]) + subprocess.call(["mkdir", CONFIG]) + subprocess.call(["mkdir", DATA]) + subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "header.txt"), CONFIG]) + subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "footer.txt"), CONFIG]) + subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "style.css"), CONFIG]) + + setup() + core.load() return "" def setup_handler(): @@ -129,7 +149,8 @@ def setup(): index = open(os.path.join(publishing, "index.html"), "w") index.write("

ttbp blog placeholder

") index.close() - subprocess.call(["rm", WWW]) + if os.path.exists(WWW): + subprocess.call(["rm", WWW]) subprocess.call(["ln", "-s", publishing, WWW]) print("\npublishing to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/\n\n") @@ -138,6 +159,8 @@ def setup(): 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 to continue.") + return SETTINGS ## menus @@ -164,7 +187,7 @@ def main_menu(): "send feedback", "see credits"] #print(SPACER) - print("you're at ttbp home now. remember, you can always press ctrl-c to come back here.\n\n") + print("you're at ttbp home. remember, you can always press to come back here.\n\n") print_menu(menuOptions) #print("how are you feeling today? ") @@ -175,7 +198,9 @@ def main_menu(): return main_menu() if choice == '0': - redraw(DUST) + redraw() + today = time.strftime("%Y%m%d") + write_entry(os.path.join(DATA, today+".txt")) elif choice == '1': redraw(DUST) elif choice == '2': @@ -213,8 +238,12 @@ def feedback_menu(): def write_entry(entry=os.path.join(DATA, "test.txt")): + raw_input("\nfeelings will be recorded for today, "+time.strftime("%d %B %Y")+".\n\nif you've already started recording feelings for this day, you \ncan pick up where you left off.\n\npress to begin recording your feelings.\n\n") subprocess.call([SETTINGS["editor"], entry]) - return "wrote to "+entry + core.load_files() + core.write("index.html") + redraw("new entry posted to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/index.html\n\nthanks for sharing your feelings!") + return def send_feedback(subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+str(int(time.time()))+".msg")): diff --git a/bin/update.py b/bin/update.py index cf56c50..716761a 100644 --- a/bin/update.py +++ b/bin/update.py @@ -2,4 +2,5 @@ import core +core.load() print("\n blog updated at "+core.write("index.html")+"\n") diff --git a/lib/lang.json b/lib/lang.json index e2df888..aa7b709 100644 --- a/lib/lang.json +++ b/lib/lang.json @@ -6,19 +6,19 @@ "good morning", "good afternoon", "good day", - "good evening" + "good evening", + "welcome back" ], "bye":[ - "see you later", - "bye", - "later" + "see you later, space cowboy", + "bye, townie", + "until next time, friend" ], "friend":[ "friend", "pal", "buddy", - "townie", - "fellow" + "townie" ], "months":{ "01":"january",