working on private blogging
first, breaking out all the setup optiosn into smaller functions for better readability. adding an option to set blog to be published or not, and checks this before printing public feels list.master
parent
e2bde9a42a
commit
fecb5b9907
169
bin/_ttbp.py
169
bin/_ttbp.py
|
@ -189,42 +189,56 @@ def setup():
|
||||||
global SETTINGS
|
global SETTINGS
|
||||||
|
|
||||||
# editor selection
|
# editor selection
|
||||||
print_menu(EDITORS)
|
SETTINGS.update({"editor": select_editor()})
|
||||||
choice = raw_input("\npick your favorite text editor: ")
|
|
||||||
while choice not in ['0', '1', '2', '3', '4']:
|
|
||||||
choice = raw_input("\nplease pick a number from the list: ")
|
|
||||||
|
|
||||||
SETTINGS["editor"] = EDITORS[int(choice)]
|
|
||||||
redraw("text editor set to: "+SETTINGS["editor"])
|
redraw("text editor set to: "+SETTINGS["editor"])
|
||||||
|
|
||||||
|
# set up public publish option
|
||||||
|
#publish = input_yn("""\
|
||||||
|
#do you want to publish your feels online?
|
||||||
|
|
||||||
|
#if yes, i'll make a directory in your public_html where your blog posts
|
||||||
|
#will be published. if not, your posts will only be readable from
|
||||||
|
#within the tilde.town network.
|
||||||
|
|
||||||
|
#you can change this option any time.
|
||||||
|
|
||||||
|
#please enter\
|
||||||
|
#""")
|
||||||
|
SETTINGS.update({"publishing":select_publishing()})
|
||||||
|
redraw("blog publishing: "+str(publishing()))
|
||||||
|
|
||||||
# publish directory selection
|
# publish directory selection
|
||||||
if SETTINGS["publish dir"]:
|
#if SETTINGS["publish dir"]:
|
||||||
print("\tcurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])+"\n\n")
|
# print("\tcurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])+"\n\n")
|
||||||
choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ")
|
#choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ")
|
||||||
if not choice:
|
#if not choice:
|
||||||
choice = "blog"
|
# choice = "blog"
|
||||||
|
|
||||||
publishing = os.path.join(PUBLIC, choice)
|
#publishing = os.path.join(PUBLIC, choice)
|
||||||
while os.path.exists(publishing):
|
#while os.path.exists(publishing):
|
||||||
second = raw_input("\n"+publishing+" already exists!\nif you're sure you want to use it, hit <enter> to confirm. otherwise, pick another location: ")
|
# second = raw_input("\n"+publishing+" already exists!\nif you're sure you want to use it, hit <enter> to confirm. otherwise, pick another location: ")
|
||||||
if second == "":
|
# if second == "":
|
||||||
break
|
# break
|
||||||
choice = second
|
# choice = second
|
||||||
publishing = os.path.join(PUBLIC, choice)
|
# publishing = os.path.join(PUBLIC, choice)
|
||||||
|
|
||||||
SETTINGS["publish dir"] = choice
|
#SETTINGS.update({"publish dir": choice})
|
||||||
|
if publishing():
|
||||||
|
SETTINGS.update({"publish dir": select_publish_dir()})
|
||||||
|
|
||||||
# set up publish directory
|
# set up publish directory
|
||||||
if not os.path.exists(publishing):
|
#publishing = os.path.join(PUBLIC, SETTINGS.get("publish dir"))
|
||||||
subprocess.call(["mkdir", publishing])
|
#if not os.path.exists(publishing):
|
||||||
subprocess.call(["touch", os.path.join(publishing, "index.html")])
|
# subprocess.call(["mkdir", publishing])
|
||||||
index = open(os.path.join(publishing, "index.html"), "w")
|
# subprocess.call(["touch", os.path.join(publishing, "index.html")])
|
||||||
index.write("<h1>ttbp blog placeholder</h1>")
|
# index = open(os.path.join(publishing, "index.html"), "w")
|
||||||
index.close()
|
# index.write("<h1>ttbp blog placeholder</h1>")
|
||||||
if os.path.exists(WWW):
|
# index.close()
|
||||||
subprocess.call(["rm", WWW])
|
#if os.path.exists(WWW):
|
||||||
subprocess.call(["ln", "-s", publishing, WWW])
|
# subprocess.call(["rm", WWW])
|
||||||
print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS["publish dir"]+"/\n\n")
|
#subprocess.call(["ln", "-s", publishing, WWW])
|
||||||
|
#print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS.get("publish dir")+"/\n\n")
|
||||||
|
make_publish_dir()
|
||||||
|
|
||||||
# save settings
|
# save settings
|
||||||
ttbprc = open(TTBPRC, "w")
|
ttbprc = open(TTBPRC, "w")
|
||||||
|
@ -283,8 +297,9 @@ def main_menu():
|
||||||
redraw("now viewing most recent entries\n\n")
|
redraw("now viewing most recent entries\n\n")
|
||||||
view_feed()
|
view_feed()
|
||||||
elif choice == '4':
|
elif choice == '4':
|
||||||
pretty_settings = "\n\ttext editor:\t" +SETTINGS["editor"]
|
pretty_settings = "\n\ttext editor:\t" +SETTINGS.get("editor")
|
||||||
pretty_settings += "\n\tpublish dir:\t" +os.path.join(PUBLIC, SETTINGS["publish dir"])
|
pretty_settings += "\n\tpublish dir:\t" +os.path.join(PUBLIC, SETTINGS.get("publish dir"))
|
||||||
|
pretty_settings += "\n\tpubishing:\t"+str(SETTINGS.get("publishing"))
|
||||||
|
|
||||||
redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this.\n\ncurrent settings "+pretty_settings+"\n")
|
redraw("now changing your settings. press <ctrl-c> if you didn't mean to do this.\n\ncurrent settings "+pretty_settings+"\n")
|
||||||
try:
|
try:
|
||||||
|
@ -336,7 +351,7 @@ def view_neighbors(users):
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))
|
userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))
|
||||||
url = LIVE+user+"/"+userRC["publish dir"]
|
url = LIVE+user+"/"+userRC.get("publish dir")
|
||||||
count = 0
|
count = 0
|
||||||
lastfile = ""
|
lastfile = ""
|
||||||
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
||||||
|
@ -538,8 +553,13 @@ def www_neighbors(users):
|
||||||
userList = []
|
userList = []
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
|
if not publishing(user):
|
||||||
|
continue
|
||||||
|
|
||||||
userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))
|
userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))
|
||||||
|
|
||||||
url = LIVE+user+"/"+userRC["publish dir"]
|
url = LIVE+user+"/"+userRC["publish dir"]
|
||||||
|
|
||||||
lastfile = ""
|
lastfile = ""
|
||||||
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
||||||
files.sort()
|
files.sort()
|
||||||
|
@ -590,6 +610,91 @@ def list_select(options, prompt):
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def input_yn(query):
|
||||||
|
# returns boolean True or False
|
||||||
|
|
||||||
|
ans = raw_input(query+" [y/n] ")
|
||||||
|
|
||||||
|
while ans not in ["y", "n"]:
|
||||||
|
ans = raw_input("'y' or 'n' please: ")
|
||||||
|
|
||||||
|
if ans == "y":
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def publishing(username = USER):
|
||||||
|
# checks .ttbprc for whether or not user wants their blog published online
|
||||||
|
|
||||||
|
ttbprc = {}
|
||||||
|
|
||||||
|
if username == USER:
|
||||||
|
ttbprc = SETTINGS
|
||||||
|
|
||||||
|
else:
|
||||||
|
ttbprc = json.load(open(os.path.join("/home", username, ".ttbp", "config", "ttbprc")))
|
||||||
|
|
||||||
|
return ttbprc.get("publishing")
|
||||||
|
|
||||||
|
def select_editor():
|
||||||
|
# setup helper for editor selection
|
||||||
|
|
||||||
|
print_menu(EDITORS)
|
||||||
|
choice = raw_input("\npick your favorite text editor: ")
|
||||||
|
while choice not in ['0', '1', '2', '3', '4']:
|
||||||
|
choice = raw_input("\nplease pick a number from the list: ")
|
||||||
|
|
||||||
|
return EDITORS[int(choice)]
|
||||||
|
|
||||||
|
def select_publish_dir():
|
||||||
|
# setup helper for publish directory selection
|
||||||
|
|
||||||
|
if SETTINGS["publish dir"]:
|
||||||
|
print("\tcurrent publish dir:\t"+os.path.join(PUBLIC, SETTINGS["publish dir"])+"\n\n")
|
||||||
|
choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ")
|
||||||
|
if not choice:
|
||||||
|
choice = "blog"
|
||||||
|
|
||||||
|
publishing = os.path.join(PUBLIC, choice)
|
||||||
|
while os.path.exists(publishing):
|
||||||
|
second = raw_input("\n"+publishing+" already exists!\nif you're sure you want to use it, hit <enter> to confirm. otherwise, pick another location: ")
|
||||||
|
if second == "":
|
||||||
|
break
|
||||||
|
choice = second
|
||||||
|
publishing = os.path.join(PUBLIC, choice)
|
||||||
|
|
||||||
|
return choice
|
||||||
|
|
||||||
|
def select_publishing():
|
||||||
|
# setup helper for toggling publishing
|
||||||
|
|
||||||
|
return input_yn("""\
|
||||||
|
do you want to publish your feels online?
|
||||||
|
|
||||||
|
if yes, i'll make a directory in your public_html where your blog posts
|
||||||
|
will be published. if not, your posts will only be readable from
|
||||||
|
within the tilde.town network.
|
||||||
|
|
||||||
|
you can change this option any time.
|
||||||
|
|
||||||
|
please enter\
|
||||||
|
""")
|
||||||
|
|
||||||
|
def make_publish_dir():
|
||||||
|
# setup helper to create publishing directory
|
||||||
|
|
||||||
|
publishing = os.path.join(PUBLIC, SETTINGS.get("publish dir"))
|
||||||
|
if not os.path.exists(publishing):
|
||||||
|
subprocess.call(["mkdir", publishing])
|
||||||
|
subprocess.call(["touch", os.path.join(publishing, "index.html")])
|
||||||
|
index = open(os.path.join(publishing, "index.html"), "w")
|
||||||
|
index.write("<h1>ttbp blog placeholder</h1>")
|
||||||
|
index.close()
|
||||||
|
if os.path.exists(WWW):
|
||||||
|
subprocess.call(["rm", WWW])
|
||||||
|
subprocess.call(["ln", "-s", publishing, WWW])
|
||||||
|
print("\n\tpublishing to "+LIVE+USER+"/"+SETTINGS.get("publish dir")+"/\n\n")
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
|
||||||
start()
|
start()
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
| |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ |
|
| |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ |
|
||||||
| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ |
|
| | |___ |___ |___ ___] |___ | \| |__] | | \| |___ |
|
||||||
| |
|
| |
|
||||||
| ver 0.8.0 (almost stable) |
|
| ver 0.8.5 (almost stable) |
|
||||||
| ~endorphant/projects/ttbp/changelog.txt |
|
| ~endorphant/projects/ttbp/changelog.txt |
|
||||||
|__________________________________________________________|
|
|__________________________________________________________|
|
||||||
|
|
|
@ -187,7 +187,7 @@ def write_global_feed(blogList):
|
||||||
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
|
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>tilde.town global feels engine</title>
|
<title>tilde.town feels engine</title>
|
||||||
<link rel=\"stylesheet\" href=\"style.css\" />
|
<link rel=\"stylesheet\" href=\"style.css\" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -202,6 +202,7 @@ def write_global_feed(blogList):
|
||||||
<p> </p>
|
<p> </p>
|
||||||
|
|
||||||
<h3>live feels-sharing:</h3>
|
<h3>live feels-sharing:</h3>
|
||||||
|
<p><i>(time not exactly to scale)</i></p>
|
||||||
<div class=\"feed\">
|
<div class=\"feed\">
|
||||||
<ul>
|
<ul>
|
||||||
""")
|
""")
|
||||||
|
|
36
bin/ttbp.py
36
bin/ttbp.py
|
@ -270,6 +270,7 @@ def main_menu():
|
||||||
redraw()
|
redraw()
|
||||||
today = time.strftime("%Y%m%d")
|
today = time.strftime("%Y%m%d")
|
||||||
write_entry(os.path.join(DATA, today+".txt"))
|
write_entry(os.path.join(DATA, today+".txt"))
|
||||||
|
www_neighbors(find_ttbps())
|
||||||
elif choice == '1':
|
elif choice == '1':
|
||||||
redraw("here are your recorded feels, listed by date:\n\n")
|
redraw("here are your recorded feels, listed by date:\n\n")
|
||||||
view_own()
|
view_own()
|
||||||
|
@ -340,7 +341,6 @@ def view_neighbors(users):
|
||||||
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
||||||
files.sort()
|
files.sort()
|
||||||
for filename in files:
|
for filename in files:
|
||||||
#if os.path.splitext(filename)[1] == ".txt" and len(os.path.splitext(filename)[0]) == 8:
|
|
||||||
if core.valid(filename):
|
if core.valid(filename):
|
||||||
count += 1
|
count += 1
|
||||||
lastfile = os.path.join("/home", user, ".ttbp", "entries", filename)
|
lastfile = os.path.join("/home", user, ".ttbp", "entries", filename)
|
||||||
|
@ -531,6 +531,40 @@ def find_ttbps():
|
||||||
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
def www_neighbors(users):
|
||||||
|
# takes a raw list of valid users and formats for www view
|
||||||
|
|
||||||
|
userList = []
|
||||||
|
|
||||||
|
for user in users:
|
||||||
|
userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))
|
||||||
|
url = LIVE+user+"/"+userRC["publish dir"]
|
||||||
|
lastfile = ""
|
||||||
|
files = os.listdir(os.path.join("/home", user, ".ttbp", "entries"))
|
||||||
|
files.sort()
|
||||||
|
for filename in files:
|
||||||
|
if core.valid(filename):
|
||||||
|
lastfile = os.path.join("/home", user, ".ttbp", "entries", filename)
|
||||||
|
|
||||||
|
ago = "never"
|
||||||
|
if lastfile:
|
||||||
|
last = os.path.getctime(lastfile)
|
||||||
|
since = time.time()-last
|
||||||
|
ago = util.pretty_time(int(since)) + " ago"
|
||||||
|
else:
|
||||||
|
last = 0
|
||||||
|
|
||||||
|
userList.append(["<a href=\""+url+"\">~"+user+"</a> ("+ago+")", last])
|
||||||
|
|
||||||
|
# sort user by most recent entry
|
||||||
|
userList.sort(key = lambda userdata:userdata[1])
|
||||||
|
userList.reverse()
|
||||||
|
sortedUsers = []
|
||||||
|
for user in userList:
|
||||||
|
sortedUsers.append(user[0])
|
||||||
|
|
||||||
|
core.write_global_feed(sortedUsers)
|
||||||
|
|
||||||
def list_select(options, prompt):
|
def list_select(options, prompt):
|
||||||
# runs the prompt for the list until a valid index is imputted
|
# runs the prompt for the list until a valid index is imputted
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ CHANGELOG:
|
||||||
|
|
||||||
ver 0.8.5
|
ver 0.8.5
|
||||||
-publish feels directory to ~endorphant/ttbp/index.html
|
-publish feels directory to ~endorphant/ttbp/index.html
|
||||||
|
-(beta only) colorized menus
|
||||||
|
|
||||||
ver 0.8.0
|
ver 0.8.0
|
||||||
-markdown parsing for entries
|
-markdown parsing for entries
|
||||||
-(beta only) colorized menus
|
|
||||||
|
|
||||||
ver 0.7.5
|
ver 0.7.5
|
||||||
-COLORFUL BANNER
|
-COLORFUL BANNER
|
||||||
|
|
Loading…
Reference in New Issue