From d50c4d5d2cea57fb34a86943cc5b23df7956463b Mon Sep 17 00:00:00 2001 From: endorphant Date: Sat, 30 Apr 2016 20:19:00 -0400 Subject: [PATCH] added chatter function --- bin/chatter.py | 14 ++++++++++++++ bin/core.py | 5 ++--- bin/ttbp.py | 21 ++++++++++++++------- lib/lang.json | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 bin/chatter.py create mode 100644 lib/lang.json diff --git a/bin/chatter.py b/bin/chatter.py new file mode 100644 index 0000000..c027854 --- /dev/null +++ b/bin/chatter.py @@ -0,0 +1,14 @@ +#!/usr/bin/python + +import random +import json +import os + +SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp") +langfile = open(os.path.join(SOURCE, "lib", "lang.json"), 'r') +LANG = json.load(langfile) +langfile.close() + +def say(keyword): + + return random.choice(LANG.get(keyword)) diff --git a/bin/core.py b/bin/core.py index 8aa982a..3eb7f62 100644 --- a/bin/core.py +++ b/bin/core.py @@ -10,7 +10,6 @@ LIVE = "http://tilde.town/~" WWW = os.path.join(PATH, "www") CONFIG = os.path.join(PATH, "config") DATA = os.path.join(PATH, "entries") -#DATA = os.path.join("..", "data") MONTHS = { "01":"january", @@ -36,11 +35,11 @@ for file in os.listdir(DATA): filename = os.path.join(DATA, file) if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt": FILES.append(file) - print(file) + #print(file) FILES.sort() FILES.reverse() -print("found: "+str(FILES)) +#print("found: "+str(FILES)) def write(outurl="default.html"): outfile = open(os.path.join(WWW, outurl), "w") diff --git a/bin/ttbp.py b/bin/ttbp.py index 133c87c..3fdb742 100644 --- a/bin/ttbp.py +++ b/bin/ttbp.py @@ -3,18 +3,25 @@ #import core import os +import core +import chatter -PATH = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") -WWW = os.path.join(PATH, "..","www") +SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") +USER = os.path.basename(os.path.expanduser("~")) +PATH = os.path.join("/home", USER, ".ttbp") + +LIVE = "http://tilde.town/~" +WWW = os.path.join(PATH, "www") CONFIG = os.path.join(PATH, "config") -DATA = os.path.join(PATH, "..", "data") +DATA = os.path.join(PATH, "entries") BANNER = open(os.path.join(CONFIG, "banner.txt")).read() -CLOSER = "\n\tsee you later, space cowboy..." +#CLOSER = "\n\tsee you later, space cowboy..." SPACER = "\n\n\n\n" def start(): print(BANNER) + print(chatter.say("greet")+", "+chatter.say("friend")) print(SPACER) print(check_init()) @@ -29,17 +36,17 @@ def start(): print(main_menu()) def stop(): - return CLOSER + return "\n\t"+chatter.say("bye") def check_init(): if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")): - return "welcome back, friend" + return "welcome back, "+USER else: return init() def init(): print(SPACER) - return "i don't recognize you, stranger. let's make friends." + return "i don't recognize you, stranger. let's make friends. you're "+USER+", right?" def main_menu(): print(SPACER) diff --git a/lib/lang.json b/lib/lang.json new file mode 100644 index 0000000..e2df888 --- /dev/null +++ b/lib/lang.json @@ -0,0 +1,37 @@ +{ + "greet":[ + "hi", + "hey", + "howdy", + "good morning", + "good afternoon", + "good day", + "good evening" + ], + "bye":[ + "see you later", + "bye", + "later" + ], + "friend":[ + "friend", + "pal", + "buddy", + "townie", + "fellow" + ], + "months":{ + "01":"january", + "02":"february", + "03":"march", + "04":"april", + "05":"may", + "06":"june", + "07":"july", + "08":"august", + "09":"september", + "10":"october", + "11":"november", + "12":"december" + } +}