added permalinks
parent
9b8d321812
commit
0ed42304c8
46
bin/core.py
46
bin/core.py
|
@ -46,10 +46,10 @@ def load_files():
|
|||
global FILES
|
||||
|
||||
FILES = []
|
||||
for file in os.listdir(DATA):
|
||||
filename = os.path.join(DATA, file)
|
||||
for filename in os.listdir(DATA):
|
||||
filename = os.path.join(DATA, filename)
|
||||
if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt":
|
||||
FILES.append(file)
|
||||
FILES.append(filename)
|
||||
|
||||
FILES.sort()
|
||||
FILES.reverse()
|
||||
|
@ -67,8 +67,9 @@ def write(outurl="default.html"):
|
|||
|
||||
outfile.write("\n")
|
||||
|
||||
for file in FILES:
|
||||
for line in write_entry(file):
|
||||
for filename in FILES:
|
||||
write_page(filename)
|
||||
for line in write_entry(filename):
|
||||
outfile.write(line)
|
||||
|
||||
outfile.write("\n")
|
||||
|
@ -80,10 +81,35 @@ def write(outurl="default.html"):
|
|||
|
||||
return os.path.join(LIVE+USER,os.path.basename(os.path.realpath(WWW)),outurl)
|
||||
|
||||
def write_entry(file):
|
||||
def write_page(filename):
|
||||
# makes a single permalink page
|
||||
|
||||
outurl = os.path.join(WWW, "".join(parse_date(filename))+".html")
|
||||
outfile = open(outurl, "w")
|
||||
|
||||
outfile.write("<!--generated by the tilde.town blogging platform on "+time.strftime("%d %B %y")+"\nhttp://tilde.town/~endorphant/ttbp/-->\n\n")
|
||||
|
||||
for line in HEADER:
|
||||
outfile.write(line)
|
||||
|
||||
outfile.write("\n")
|
||||
|
||||
for line in write_entry(filename):
|
||||
outfile.write(line)
|
||||
|
||||
outfile.write("\n")
|
||||
|
||||
for line in FOOTER:
|
||||
outfile.write(line)
|
||||
|
||||
outfile.close()
|
||||
|
||||
return outurl
|
||||
|
||||
def write_entry(filename):
|
||||
# dump given file into entry format, return as list of strings
|
||||
|
||||
date = parse_date(file)
|
||||
date = parse_date(filename)
|
||||
|
||||
entry = [
|
||||
"\t\t<p><a name=\""+date[0]+date[1]+date[2]+"\"></a><br /><br /></p>\n",
|
||||
|
@ -93,7 +119,7 @@ def write_entry(file):
|
|||
]
|
||||
|
||||
raw = []
|
||||
rawfile = open(os.path.join(DATA, file), "r")
|
||||
rawfile = open(os.path.join(DATA, filename), "r")
|
||||
|
||||
for line in rawfile:
|
||||
raw.append(line)
|
||||
|
@ -104,7 +130,9 @@ def write_entry(file):
|
|||
if line == "\n":
|
||||
entry.append("</p>\n\t\t\t<p>")
|
||||
|
||||
entry.append("</p>\n\t\t</div>\n")
|
||||
entry.append("</p>\n")
|
||||
entry.append("\t\t\t<p style=\"font-size:.6em; font-color:#808080; text-align: right;\"><a href=\""+"".join(date)+".html\">permalink</a></p>\n")
|
||||
entry.append("\n\t\t</div>\n")
|
||||
|
||||
return entry
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
27
bin/ttbp.py
27
bin/ttbp.py
|
@ -9,12 +9,14 @@ import json
|
|||
|
||||
import core
|
||||
import chatter
|
||||
import inflect
|
||||
|
||||
## system globals
|
||||
SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin")
|
||||
LIVE = "http://tilde.town/~"
|
||||
FEEDBACK = os.path.join("/home", "endorphant", "ttbp-mail")
|
||||
USERFILE = os.path.join("/home", "endorphant", "projects", "ttbp", "users.txt")
|
||||
p = inflect.engine()
|
||||
|
||||
## user globals
|
||||
USER = os.path.basename(os.path.expanduser("~"))
|
||||
|
@ -126,7 +128,7 @@ def gen_header():
|
|||
header.append("\n\t</head>")
|
||||
header.append("\n\t<body>")
|
||||
header.append("\n\t\t<div id=\"meta\">")
|
||||
header.append("\n\t\t\t<h1><a href=\"#\">~"+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<!---put your custom html here-->\n\n\n\n")
|
||||
header.append("\n\t\t<!---don't put anything after this line-->\n")
|
||||
|
@ -243,6 +245,9 @@ def main_menu():
|
|||
feedback_menu()
|
||||
elif choice == '4':
|
||||
redraw(DUST)
|
||||
elif choice == 'secret':
|
||||
redraw("here are your recorded feelings, listed by date:\n\n")
|
||||
view_entries()
|
||||
elif choice == "none":
|
||||
return stop()
|
||||
else:
|
||||
|
@ -257,7 +262,7 @@ def feedback_menu():
|
|||
choice = raw_input("\npick a category for your feedback: ")
|
||||
|
||||
cat = ""
|
||||
if choice in ['0', '1', '2']:
|
||||
if choice in ['0', '1', '2', '3']:
|
||||
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")
|
||||
redraw(send_feedback(cat))
|
||||
|
@ -296,6 +301,7 @@ def send_feedback(subject="none", mailbox=os.path.join(FEEDBACK, USER+"-"+time.s
|
|||
return "mail sent. thanks for writing! i'll try to respond to you soon."
|
||||
|
||||
def view_neighbors():
|
||||
# TODO: rewrite this so you don't have to traverse a second list??
|
||||
|
||||
users = []
|
||||
|
||||
|
@ -306,12 +312,27 @@ def view_neighbors():
|
|||
for user in users:
|
||||
userRC = json.load(open(os.path.join("/home", user, ".ttbp", "config", "ttbprc")))
|
||||
url = LIVE+user+"/"+userRC["publish dir"]
|
||||
print("\t~"+user+"\t at "+url)
|
||||
count = 0
|
||||
for filename in os.listdir(os.path.join("/home", user, ".ttbp", "entries")):
|
||||
if os.path.splitext(filename)[1] == ".txt" and len(os.path.splitext(filename)[0]) == 8:
|
||||
count += 1
|
||||
user = "~"+user
|
||||
if len(user) < 8:
|
||||
user += "\t"
|
||||
print("\t"+user+"\t at "+url+"\t("+p.no("entry", count)+")")
|
||||
|
||||
raw_input("\n\npress <enter> to go back home.\n\n")
|
||||
redraw()
|
||||
|
||||
return
|
||||
|
||||
def view_entries():
|
||||
|
||||
entries = []
|
||||
|
||||
raw_input("\n\npress <ctrl-c> to go back home.\n\n")
|
||||
redraw()
|
||||
return
|
||||
#####
|
||||
|
||||
start()
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
TO-DO:
|
||||
(goals for stable release)
|
||||
-make individual permalink pages
|
||||
-add credits page
|
||||
-browse own entries
|
||||
-show most recent global entries
|
||||
-filename validator (only process entries if they're
|
||||
. ttbp/entries/YYMMDD.txt")
|
||||
|
||||
------
|
||||
|
||||
|
|
Loading…
Reference in New Issue