cleaning up a couple of print strings

master
endorphant 2016-05-15 00:22:05 -04:00
parent 8825debf96
commit b04d1a4378
2 changed files with 106 additions and 46 deletions

View File

@ -318,7 +318,8 @@ def feedback_menu():
composing a """+cat+""" to ~endorphant. composing a """+cat+""" to ~endorphant.
press <enter> to open an external text editor. mail will be sent once you save and quit. press <enter> to open an external text editor. mail will be sent once you save and quit.
""")
""")
redraw(send_feedback(entered, cat)) redraw(send_feedback(entered, cat))
return return
else: else:
@ -394,8 +395,8 @@ def show_credits():
ttbp was written by ~endorphant in python. the codebase is ttbp was written by ~endorphant in python. the codebase is
publicly available on github at https://github.com/modgethanc/ttbp publicly available on github at https://github.com/modgethanc/ttbp
if you have ideas for ttbp, you are welcome to fork the repo and if you have ideas for ttbp, you are welcome to fork the repo and
work on it. i'm only a neophyte dev, so i apologize for any work on it. i'm only a neophyte dev, so i apologize for any
horrendously ugly coding habits i have. i'd love to hear about your horrendously ugly coding habits i have. i'd love to hear about your
ideas and brainstorm about new features! ideas and brainstorm about new features!
@ -419,7 +420,8 @@ if you've already started recording feels for this day, you
can pick up where you left off. can pick up where you left off.
press <enter> to begin recording your feels. press <enter> to begin recording your feels.
""")
""")
if entered: if entered:
entryFile = open(entry, "a") entryFile = open(entry, "a")
@ -454,7 +456,7 @@ def send_feedback(entered, subject="none", mailbox=os.path.join(FEEDBACK, USER+"
return """\ return """\
thanks for writing! for your reference, it's been recorded thanks for writing! for your reference, it's been recorded
> as "+ " ".join([subject, id])+". i'll try to respond to you soon.\ > as """+ " ".join([subject, id])+""". i'll try to respond to you soon.\
""" """
def view_entries(metas, entries, prompt): def view_entries(metas, entries, prompt):

View File

@ -6,6 +6,7 @@ import tempfile
import subprocess import subprocess
import time import time
import json import json
from email.mime.text import MIMEText;
import core import core
import chatter import chatter
@ -16,6 +17,7 @@ import util
SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin")
LIVE = "http://tilde.town/~" LIVE = "http://tilde.town/~"
FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail") FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail")
FEEDBOX = "endorphant@tilde.town"
USERFILE = os.path.join("/home", "endorphant", "projects", "ttbp", "users.txt") USERFILE = os.path.join("/home", "endorphant", "projects", "ttbp", "users.txt")
p = inflect.engine() p = inflect.engine()
@ -33,7 +35,7 @@ SETTINGS = {
} }
## ui globals ## ui globals
BANNER = open(os.path.join(SOURCE, "config", "banner.txt")).read() BANNER = util.attach_rainbow()+open(os.path.join(SOURCE, "config", "banner.txt")).read()+util.attach_reset()
SPACER = "\n\n\n" SPACER = "\n\n\n"
INVALID = "please pick a number from the list of options!\n\n" INVALID = "please pick a number from the list of options!\n\n"
DUST = "sorry about the dust, but this part is still under construction. check back later!\n\n" DUST = "sorry about the dust, but this part is still under construction. check back later!\n\n"
@ -59,7 +61,11 @@ def start():
redraw() redraw()
#print(chatter.say("greet")+", "+chatter.say("friend")) #print(chatter.say("greet")+", "+chatter.say("friend"))
#print("(remember, you can always press ctrl-c to come home)\n") #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 <ctrl-d> and it'll all go away.
just keep in mind that you might lose anything you've started here.\
""")
try: try:
print(check_init()) print(check_init())
except EOFError: except EOFError:
@ -102,7 +108,11 @@ def check_init():
def init(): def init():
try: try:
raw_input("i don't recognize you, stranger. let's make friends.\n\npress <enter> to begin, or <ctrl-c> to get out of here. \n\n") raw_input("""
i don't recognize you, stranger. let's make friends.
press <enter> to begin, or <ctrl-c> to get out of here.
""")
except KeyboardInterrupt: except KeyboardInterrupt:
print("\n\nthanks for checking in! i'll always be here.\n\n") print("\n\nthanks for checking in! i'll always be here.\n\n")
quit() quit()
@ -113,12 +123,13 @@ def init():
subprocess.call(["mkdir", PATH]) subprocess.call(["mkdir", PATH])
subprocess.call(["mkdir", CONFIG]) subprocess.call(["mkdir", CONFIG])
subprocess.call(["mkdir", DATA]) subprocess.call(["mkdir", DATA])
#subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "header.txt"), CONFIG])
header = gen_header() header = gen_header()
headerfile = open(os.path.join(CONFIG, "header.txt"), 'w') headerfile = open(os.path.join(CONFIG, "header.txt"), 'w')
for line in header: for line in header:
headerfile.write(line) headerfile.write(line)
headerfile.close() headerfile.close()
subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "footer.txt"), CONFIG]) subprocess.call(["cp", os.path.join(SOURCE, "config", "defaults", "footer.txt"), CONFIG])
setup() setup()
@ -129,21 +140,41 @@ def init():
return "" return ""
def gen_header(): def gen_header():
header = [] #header = []
header.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">") #header.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">")
header.append("\n<html>") #header.append("\n<html>")
header.append("\n\t<head>") #header.append("\n\t<head>")
header.append("\n\t\t<title>~"+USER+" on TTBP</title>") #header.append("\n\t\t<title>~"+USER+" on TTBP</title>")
header.append("\n\t\t<link rel=\"stylesheet\" href=\"style.css\" />") #header.append("\n\t\t<link rel=\"stylesheet\" href=\"style.css\" />")
header.append("\n\t</head>") #header.append("\n\t</head>")
header.append("\n\t<body>") #header.append("\n\t<body>")
header.append("\n\t\t<div id=\"meta\">") #header.append("\n\t\t<div id=\"meta\">")
header.append("\n\t\t\t<h1><a href=\"index.html#\">~"+USER+"</a>@<a href=\"/~endorphant/ttbp\">TTBP</a></h1>") #header.append("\n\t\t\t<h1><a href=\"index.html#\">~"+USER+"</a>@<a href=\"/~endorphant/ttbp\">TTBP</a></h1>")
header.append("\n\t\t</div>\n") #header.append("\n\t\t</div>\n")
header.append("\n\t\t<!---put your custom html here-->\n\n\n\n") #header.append("\n\t\t<!---put your custom html here-->\n\n\n\n")
header.append("\n\t\t<!---don't put anything after this line-->\n") #header.append("\n\t\t<!---don't put anything after this line-->\n")
header.append("\n\t\t<div id=\"tlogs\">\n") #header.append("\n\t\t<div id=\"tlogs\">\n")
header ="""
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
<html>
<head>
<title>~"""+USER+""" on TTBP</title>
<link rel=\"stylesheet\" href=\"style.css\" />
</head>
<body>
<div id=\"meta\">
<h1><a href=\"index.html#\">~"""+USER+"""</a>@<a href=\"/~endorphant/ttbp\">TTBP</a></h1>
</div>
<!---put your custom html here-->
<!---don't put anything after this line-->
<div id=\"tlogs\">\
"""
return header return header
def setup_handler(): def setup_handler():
@ -283,8 +314,13 @@ def feedback_menu():
cat = "" cat = ""
if choice in ['0', '1', '2', '3']: if choice in ['0', '1', '2', '3']:
cat = SUBJECTS[int(choice)] cat = SUBJECTS[int(choice)]
raw_input("\ncomposing a "+cat+" to ~endorphant.\n\npress <enter> to open an external text editor. mail will be sent once you save and quit.\n") entered = raw_input("""
redraw(send_feedback(cat)) composing a """+cat+""" to ~endorphant.
press <enter> to open an external text editor. mail will be sent once you save and quit.
""")
redraw(send_feedback(entered, cat))
return return
else: else:
redraw(INVALID) redraw(INVALID)
@ -355,7 +391,17 @@ def view_own():
def show_credits(): def show_credits():
print("ttbp was written by ~endorphant in python. the codebase is\npublicly available on github at https://github.com/modgethanc/ttbp\n\nif you have ideas for ttbp, you are welcome to fork the repo and \nwork on it. i'm only a baby dev, so i apologize for any \nhorrendously ugly coding habits i have.\n\nthanks to everyone who reads, listens, writes, and feels.") print("""
ttbp was written by ~endorphant in python. the codebase is
publicly available on github at https://github.com/modgethanc/ttbp
if you have ideas for ttbp, you are welcome to fork the repo and
work on it. i'm only a neophyte dev, so i apologize for any
horrendously ugly coding habits i have. i'd love to hear about your
ideas and brainstorm about new features!
thanks to everyone who reads, listens, writes, and feels.\
""")
raw_input("\n\npress <enter> to go back home.\n\n") raw_input("\n\npress <enter> to go back home.\n\n")
redraw() redraw()
@ -367,7 +413,16 @@ def show_credits():
def write_entry(entry=os.path.join(DATA, "test.txt")): def write_entry(entry=os.path.join(DATA, "test.txt")):
entered = raw_input("\nfeels will be recorded for today, "+time.strftime("%d %B %Y")+".\n\nif you've already started recording feels for this day, you \ncan pick up where you left off.\n\npress <enter> to begin recording your feels.\n\n") 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.
press <enter> to begin recording your feels.
""")
if entered: if entered:
entryFile = open(entry, "a") entryFile = open(entry, "a")
entryFile.write("\n"+entered+"\n") entryFile.write("\n"+entered+"\n")
@ -378,22 +433,31 @@ def write_entry(entry=os.path.join(DATA, "test.txt")):
redraw("posted to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/index.html\n\nthanks for sharing your feels!") redraw("posted to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/index.html\n\nthanks for sharing your feels!")
return return
def send_feedback(subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+time.strftime("%Y%m%d-%H%M")+".msg")): def send_feedback(entered, subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+time.strftime("%Y%m%d-%H%M")+".msg")):
mail = "" message = ""
temp = tempfile.NamedTemporaryFile() temp = tempfile.NamedTemporaryFile()
if entered:
msgFile = open(temp.name, "a")
msgFile.write(entered+"\n")
msgFile.close()
subprocess.call([SETTINGS["editor"], temp.name]) subprocess.call([SETTINGS["editor"], temp.name])
mail = open(temp.name, 'r').read() message = open(temp.name, 'r').read()
outfile = open(mailbox, 'w') id = "#"+util.genID(3)
outfile.write("from:\t\t~"+USER+"\n") mail = MIMEText(message)
outfile.write("subject:\t"+subject+"\n") mail['To'] = FEEDBOX
outfile.write("date:\t"+time.strftime("%d %B %y")+"\n") mail['From'] = USER+"@tilde.town"
outfile.write(mail) mail['Subject'] = " ".join(["[ttbp]", subject, id])
outfile.close() m = os.popen("/usr/sbin/sendmail -t -oi", 'w')
m.write(mail.as_string())
m.close()
return "mail sent. thanks for writing! i'll try to respond to you soon." return """\
thanks for writing! for your reference, it's been recorded
> as """+ " ".join([subject, id])+""". i'll try to respond to you soon.\
"""
def view_entries(metas, entries, prompt): def view_entries(metas, entries, prompt):
@ -427,10 +491,8 @@ def view_feed():
for townie in find_ttbps(): for townie in find_ttbps():
entryDir = os.path.join("/home", townie, ".ttbp", "entries") entryDir = os.path.join("/home", townie, ".ttbp", "entries")
filenames = os.listdir(entryDir) filenames = os.listdir(entryDir)
for entry in filenames: for entry in filenames:
### REALLY MAKE A REAL FILENAME VALIDATOR
#fileSplit = os.path.splitext(entry)
#if len(fileSplit[0]) == 8 and fileSplit[1] == ".txt":
if core.valid(entry): if core.valid(entry):
feedList.append(os.path.join(entryDir, entry)) feedList.append(os.path.join(entryDir, entry))
@ -452,6 +514,7 @@ def view_feed():
redraw() redraw()
return return
##### #####
def find_ttbps(): def find_ttbps():
@ -471,13 +534,8 @@ def list_select(options, prompt):
invalid = True invalid = True
while invalid: while invalid:
#try:
# choice = raw_input("\n\n"+prompt)
#except KeyboardInterrupt:
# redraw()
# main_menu()
choice = raw_input("\n\n"+prompt) choice = raw_input("\n\n"+prompt)
if choice in BACKS: if choice in BACKS:
return False return False