From a82c25840e366ce0ce7869425adf2023605062e9 Mon Sep 17 00:00:00 2001 From: endorphant Date: Wed, 11 May 2016 00:10:04 -0400 Subject: [PATCH] incremented to version 0.7 added filename validator --- bin/config/banner.txt | 2 +- bin/core.py | 30 ++++++++++++++++++++++++------ bin/ttbp.py | 24 ++++++++---------------- changelog.txt | 10 ++++------ 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/bin/config/banner.txt b/bin/config/banner.txt index 0e26950..8cf63e5 100644 --- a/bin/config/banner.txt +++ b/bin/config/banner.txt @@ -5,6 +5,6 @@ | |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | | | -| ver 0.6.5 (fairly unstable) | +| ver 0.7.0 (almost stable) | | ~endorphant/projects/ttbp/changelog.txt | |__________________________________________________________| diff --git a/bin/core.py b/bin/core.py index cbed5ce..eb6d353 100644 --- a/bin/core.py +++ b/bin/core.py @@ -3,6 +3,7 @@ import os import time import subprocess +import re import chatter @@ -49,7 +50,8 @@ def load_files(): FILES = [] for filename in os.listdir(DATA): filename = os.path.join(DATA, filename) - if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt": + #if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt": + if os.path.isfile(filename) and valid(filename): FILES.append(filename) FILES.sort() @@ -63,9 +65,6 @@ def write(outurl="default.html"): for line in HEADER: outfile.write(line) - #for line in write_placeholder(): - # outfile.write(line) - outfile.write("\n") for filename in FILES: @@ -171,12 +170,31 @@ def meta(entries = FILES): meta.sort(key = lambda filename:filename[4]) meta.reverse() + return meta +def valid(filename): + # check if the filename is YYYYMMDD.txt + + filesplit = os.path.splitext(os.path.basename(filename)) + + if filesplit[1] != ".txt": + return False + + pattern = '^((19|20)\d{2})(0[1-9]|1[0-2])(0[1-9]|1\d|2\d|3[01])$' + + if not re.match(pattern, filesplit[0]): + return False + + return True + + +############# +############# +############# + def test(): load() - #for x in FILES: - # print(x) metaTest = meta() diff --git a/bin/ttbp.py b/bin/ttbp.py index 5ac47ff..aacd1a4 100644 --- a/bin/ttbp.py +++ b/bin/ttbp.py @@ -216,9 +216,6 @@ def print_menu(menu): i += 1 def main_menu(): - #os.system("clear") - #print(BANNER) - #redraw() menuOptions = [ "record your feels", "review your feels", @@ -226,18 +223,11 @@ def main_menu(): "browse global feels", "change your settings", "send some feedback", - "(wip) see credits"] - #print(SPACER) - #print("you're at ttbp home. remember, you can always press to come back here.\n\n") - print("you're at ttbp home.\n\n") + "see credits"] + print("you're at ttbp home. remember, you can always press to come back here.\n\n") + #print("you're at ttbp home.\n\n") print_menu(menuOptions) - #print("how are you feeling today? ") - #try: - # choice = raw_input("\ntell me about your feels (or 'quit' to exit): ") - #except KeyboardInterrupt: - # redraw(EJECT) - # return main_menu() try: choice = raw_input("\ntell me about your feels (or 'quit' to exit): ") except KeyboardInterrupt: @@ -313,7 +303,8 @@ def view_neighbors(users): files = os.listdir(os.path.join("/home", user, ".ttbp", "entries")) files.sort() for filename in files: - if os.path.splitext(filename)[1] == ".txt" and len(os.path.splitext(filename)[0]) == 8: + #if os.path.splitext(filename)[1] == ".txt" and len(os.path.splitext(filename)[0]) == 8: + if core.valid(filename): count += 1 lastfile = os.path.join("/home", user, ".ttbp", "entries", filename) @@ -438,8 +429,9 @@ def view_feed(): filenames = os.listdir(entryDir) for entry in filenames: ### REALLY MAKE A REAL FILENAME VALIDATOR - fileSplit = os.path.splitext(entry) - if len(fileSplit[0]) == 8 and fileSplit[1] == ".txt": + #fileSplit = os.path.splitext(entry) + #if len(fileSplit[0]) == 8 and fileSplit[1] == ".txt": + if core.valid(entry): feedList.append(os.path.join(entryDir, entry)) metas = core.meta(feedList) diff --git a/changelog.txt b/changelog.txt index fb931fa..5b60eeb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,18 +1,15 @@ TO-DO: (goals for stable release) - -filename validator - -only count/process entries if filename is - .ttbp/entries/YYMMDD.txt" -show most recent global entries on html - -make commenting actually use mail instead of dumping - to a file? - -command line flags + -command line flags: + -shortcut to most recent feels, writing entry, seeing own entry -markdown parsing -neighbor view takes you to individual entry listing (goals for phase two) + -make feedback actually use mail instead of dumping to a file -stylesheet selector -and make a couple more custom stylesheets -replying to entries?? @@ -29,6 +26,7 @@ CHANGELOG: ver 0.7 -fixed program crashing? maybe? -added credits + -added filename validator ver 0.6.5 -renamed FEELS ENGINE