added chatter function
This commit is contained in:
		
							parent
							
								
									6dab09e611
								
							
						
					
					
						commit
						d50c4d5d2c
					
				
							
								
								
									
										14
									
								
								bin/chatter.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								bin/chatter.py
									
									
									
									
									
										Normal file
									
								
							@ -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))
 | 
			
		||||
@ -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")
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								bin/ttbp.py
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								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)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										37
									
								
								lib/lang.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								lib/lang.json
									
									
									
									
									
										Normal file
									
								
							@ -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"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user