2016-04-30 03:17:06 +00:00
#!/usr/bin/python
import os
2016-05-01 17:44:49 +00:00
import random
import tempfile
import subprocess
import time
2016-05-01 18:10:04 +00:00
#import core
2016-05-01 00:19:00 +00:00
import chatter
2016-04-30 03:17:06 +00:00
2016-05-01 00:19:00 +00:00
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 " )
2016-04-30 03:48:01 +00:00
CONFIG = os . path . join ( PATH , " config " )
2016-05-01 00:19:00 +00:00
DATA = os . path . join ( PATH , " entries " )
2016-04-30 03:17:06 +00:00
2016-05-01 17:44:49 +00:00
FEEDBACK = os . path . join ( " /home " , " endorphant " , " ttbp-mail " )
2016-05-01 18:10:04 +00:00
BANNER = open ( os . path . join ( SOURCE , " config " , " banner.txt " ) ) . read ( )
2016-05-01 00:19:00 +00:00
#CLOSER = "\n\tsee you later, space cowboy..."
2016-05-01 17:44:49 +00:00
SPACER = " \n \n \n "
2016-05-01 18:10:04 +00:00
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 "
##
def redraw ( leftover = " " ) :
os . system ( " clear " )
print ( BANNER )
print ( SPACER )
if leftover :
print ( " > " + leftover + " \n " )
2016-04-30 03:17:06 +00:00
def start ( ) :
2016-05-01 18:10:04 +00:00
redraw ( )
2016-05-01 17:44:49 +00:00
#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. \n just keep in mind that you might lose anything you ' ve started here. \n " )
2016-04-30 03:34:43 +00:00
print ( check_init ( ) )
2016-04-30 03:17:06 +00:00
try :
2016-05-01 18:10:04 +00:00
redraw ( )
2016-04-30 03:17:06 +00:00
print ( main_menu ( ) )
except ValueError or SyntaxError :
2016-05-01 18:10:04 +00:00
redraw ( " \n \n oh no i didn ' t understand that " )
2016-04-30 03:17:06 +00:00
print ( main_menu ( ) )
except KeyboardInterrupt :
2016-05-01 18:10:04 +00:00
redraw ( " \n \n eject button fired " )
2016-04-30 03:17:06 +00:00
print ( main_menu ( ) )
2016-04-30 03:34:43 +00:00
def stop ( ) :
2016-05-01 00:19:00 +00:00
return " \n \t " + chatter . say ( " bye " )
2016-04-30 03:34:43 +00:00
def check_init ( ) :
if os . path . exists ( os . path . join ( os . path . expanduser ( " ~ " ) , " .ttbp " ) ) :
2016-05-01 18:10:04 +00:00
raw_input ( " welcome back, " + USER + " . \n \n press enter to explore your feelings. \n \n " )
2016-05-01 17:44:49 +00:00
return " "
2016-04-30 03:34:43 +00:00
else :
return init ( )
def init ( ) :
2016-05-01 18:10:04 +00:00
raw_input ( " i don ' t recognize you, stranger. let ' s make friends someday. \n \n press enter to explore some options. \n \n " )
2016-05-01 17:44:49 +00:00
return " "
## menus
def print_menu ( menu ) :
i = 0
for x in menu :
line = [ ]
line . append ( " \t [ " )
if i < 10 :
line . append ( " " )
line . append ( str ( i ) + " ] " + x )
print ( " " . join ( line ) )
i + = 1
2016-04-30 03:34:43 +00:00
2016-04-30 03:17:06 +00:00
def main_menu ( ) :
2016-05-01 18:10:04 +00:00
#os.system("clear")
#print(BANNER)
#redraw()
2016-05-01 17:44:49 +00:00
menuOptions = [ " record feelings " , " check out neighbors " , " send feedback " ]
2016-05-01 18:10:04 +00:00
#print(SPACER)
2016-05-01 17:44:49 +00:00
print ( " you ' re at ttbp home now. remember, you can always press ctrl-c to come back here. \n \n " )
print_menu ( menuOptions )
#print("how are you feeling today? ")
choice = raw_input ( " \n tell me about your feels (enter ' none ' to quit): " )
if choice == ' 0 ' :
2016-05-01 18:10:04 +00:00
redraw ( DUST )
2016-05-01 17:44:49 +00:00
elif choice == ' 1 ' :
2016-05-01 18:10:04 +00:00
redraw ( DUST )
2016-05-01 17:44:49 +00:00
elif choice == ' 2 ' :
2016-05-01 18:10:04 +00:00
redraw ( )
feedback_menu ( )
2016-05-01 17:44:49 +00:00
elif choice == " none " :
return stop ( )
else :
2016-05-01 18:10:04 +00:00
redraw ( INVALID )
2016-05-01 17:44:49 +00:00
return main_menu ( )
2016-04-30 03:17:06 +00:00
2016-05-01 17:44:49 +00:00
def feedback_menu ( ) :
2016-05-01 18:10:04 +00:00
print ( " you ' re about to send mail to ~endorphant about ttbp \n \n " )
menuOptions = [ " bug report " , " feature suggestion " , " general comment " ]
2016-04-30 03:17:06 +00:00
2016-05-01 17:44:49 +00:00
print_menu ( menuOptions )
choice = raw_input ( " \n pick a category for your feedback: " )
2016-04-30 03:17:06 +00:00
2016-05-01 17:44:49 +00:00
cat = " "
if choice in [ ' 0 ' , ' 1 ' , ' 2 ' ] :
cat = menuOptions [ int ( choice ) ]
2016-05-01 18:10:04 +00:00
raw_input ( " \n composing a " + cat + " to ~endorphant. \n \n press enter to open an external text editor. mail will be sent once you save and quit. \n " )
redraw ( send_feedback ( cat ) )
return
2016-05-01 17:44:49 +00:00
else :
2016-05-01 18:10:04 +00:00
redraw ( INVALID )
2016-05-01 17:44:49 +00:00
return feedback_menu ( )
## handlers
def write_entry ( entry = os . path . join ( DATA , " test.txt " ) ) :
subprocess . call ( [ " vim " , entry ] )
return " wrote to " + entry
def send_feedback ( subject = " none " , mailbox = os . path . join ( FEEDBACK , USER + " - " + str ( int ( time . time ( ) ) ) + " .msg " ) ) :
mail = " "
temp = tempfile . NamedTemporaryFile ( )
subprocess . call ( [ ' vim ' , temp . name ] )
mail = open ( temp . name , ' r ' ) . read ( )
outfile = open ( mailbox , ' w ' )
outfile . write ( " from: \t \t ~ " + USER + " \n " )
outfile . write ( " subject: \t " + subject + " \n \n " )
outfile . write ( mail )
outfile . close ( )
return " mail sent. thanks for writing! i ' ll try to respond to you soon. "
2016-04-30 03:48:01 +00:00
#####
start ( )