From d71790fff63183abcba6b45a10849e3eef1bab44 Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Fri, 23 Feb 2018 15:28:25 -0500 Subject: [PATCH 1/6] fixed raw_input error for python 3 --- ttbp/ttbp.py | 31 ++++++++++++++++--------------- ttbp/util.py | 7 ++++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 253e52b..971902b 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -40,6 +40,7 @@ import time import json from email.mime.text import MIMEText import datetime +from six.moves import input import inflect @@ -233,7 +234,7 @@ def check_init(): setup_repair() else: - raw_input("press to explore your feels.\n\n") + input("press to explore your feels.\n\n") core.load(SETTINGS) @@ -246,7 +247,7 @@ def init(): """ try: - raw_input(""" + input(""" i don't recognize you, stranger. let's make friends. press to begin, or to get out of here.""") @@ -296,7 +297,7 @@ press to begin, or to get out of here.""") setup() core.load(SETTINGS) - raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") + input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") return "" def gen_header(): @@ -396,7 +397,7 @@ def setup_repair(): print("...") time.sleep(1) - raw_input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") + input("\nyou're all good to go, "+chatter.say("friend")+"! hit to continue.\n\n") def setup(): ''' @@ -420,7 +421,7 @@ def setup(): util.print_menu(menuOptions, SETTINGS.get("rainbows", False)) try: - choice = raw_input("\npick a setting to change (or type 'q' to exit): ") + choice = input("\npick a setting to change (or type 'q' to exit): ") except KeyboardInterrupt: redraw(EJECT) return SETTINGS @@ -475,7 +476,7 @@ def setup(): save_settings() return setup() - raw_input("\nyou're all good to go, {friend}! hit to continue.\n\n".format(friend=chatter.say("friend"))) + input("\nyou're all good to go, {friend}! hit to continue.\n\n".format(friend=chatter.say("friend"))) redraw() return SETTINGS @@ -511,7 +512,7 @@ def main_menu(): util.print_menu(menuOptions, SETTINGS.get("rainbows", False)) try: - choice = raw_input("\ntell me about your feels (or type 'q' to exit): ") + choice = input("\ntell me about your feels (or type 'q' to exit): ") except KeyboardInterrupt: redraw(EJECT) return main_menu() @@ -571,12 +572,12 @@ def feedback_menu(): ''' util.print_menu(SUBJECTS, SETTINGS.get("rainbows", False)) - choice = raw_input("\npick a category for your feedback: ") + choice = input("\npick a category for your feedback: ") cat = "" if choice in ['0', '1', '2', '3']: cat = SUBJECTS[int(choice)] - entered = raw_input(""" + entered = input(""" composing a {mail_category} to ~endorphant. press to open an external text editor. mail will be sent once you save and quit. @@ -751,7 +752,7 @@ i'd love to hear about your ideas and brainstorm about new features! thanks to everyone who reads, listens, writes, and feels.\ """) - raw_input("\n\npress to go back home.\n\n") + input("\n\npress to go back home.\n\n") redraw() return @@ -763,7 +764,7 @@ def write_entry(entry=os.path.join(config.USER_DATA, "test.txt")): main feels-recording handler ''' - entered = raw_input(""" + entered = input(""" feels will be recorded for today, {today}. if you've already started recording feels for this day, you @@ -972,7 +973,7 @@ wall will be recorded if you save the file, and you can cancel your changes by exiting without saving. """) - raw_input("press to visit the wall\n\n") + input("press to visit the wall\n\n") subprocess.call([SETTINGS.get("editor"), config.WALL]) subprocess.call(["rm", config.WALL_LOCK]) redraw("thanks for visiting the graffiti wall!") @@ -1033,13 +1034,13 @@ def select_publish_dir(): print("\ncurrent publish dir:\t"+os.path.join(config.PUBLIC, SETTINGS["publish dir"])) republish = True - choice = raw_input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ") + choice = input("\nwhere do you want your blog published? (leave blank to use default \"blog\") ") if not choice: choice = "blog" publishDir = os.path.join(config.PUBLIC, choice) while os.path.exists(publishDir): - second = raw_input("\n"+publishDir+"""\ + second = input("\n"+publishDir+"""\ already exists! setting this as your publishing directory means this program may @@ -1278,7 +1279,7 @@ something strange happened to you during this update. confirm = "" while confirm not in ("x", "", "X", ""): - confirm = raw_input("\nplease type when you've finished reading about the updates! ") + confirm = input("\nplease type when you've finished reading about the updates! ") open(versionFile, "w").write(__version__) diff --git a/ttbp/util.py b/ttbp/util.py index 85707b5..5168018 100644 --- a/ttbp/util.py +++ b/ttbp/util.py @@ -25,6 +25,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import random import time +from six.moves import input import colorama import inflect @@ -179,7 +180,7 @@ def list_select(options, prompt): ans = "" invalid = True - choice = raw_input("\n"+prompt) + choice = input("\n"+prompt) if choice in BACKS: return False @@ -205,11 +206,11 @@ def input_yn(query): ''' try: - ans = raw_input(query+" [y/n] ") + ans = input(query+" [y/n] ") except KeyboardInterrupt: input_yn(query) while ans not in ["y", "n"]: - ans = raw_input("'y' or 'n' please: ") + ans = input("'y' or 'n' please: ") return ans == "y" From 8aabece380d0ef891124b394fdcc42435ea0712e Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Fri, 23 Feb 2018 15:29:19 -0500 Subject: [PATCH 2/6] removing manifesto from repo --- ttbp-manifesto.txt | 56 ---------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 ttbp-manifesto.txt diff --git a/ttbp-manifesto.txt b/ttbp-manifesto.txt deleted file mode 100644 index e35dc9d..0000000 --- a/ttbp-manifesto.txt +++ /dev/null @@ -1,56 +0,0 @@ -TTBP MANIFESTO --------------- -ttbp: tilde town blogging platform; also known as THE FEELS ENGINE - -a history: - - in april 2016, i read a short rant by ~minerobber lamenting the lack of cli - blogging software. this struck a chord with me; years ago, i kludged myself a - perl script that generated an html blog, complete with an rss feed and a - crude tagging system. i've known other people who have done the same. what's - missing, though? - - years ago, i peeled away from livejournal and related web-based blogging - networks; partially as a participant in the general attrition, and partially - to escape some personal bad feelings that i coudn't quite put a finger on. - this is why i started writing on an independent, solo blog; i still had the - urge to publicly share some of my journaling. but it felt lonely. - - this is what happens when i log in to a unix box: i reattach my screens, and - flip through irc to catch up on chat, and alpine to check my mail. in the - past, on non-tilde machines, i've fired up zephyr to message friends. i git - pull my repos for updates. i check the nethack leaderboard. these are all - cli-based actions, but they are also based on the idea that when i wasn't - looking, things changed. those things changed because other people performed - some actions of their own. i catch up on these updates with the implicit - acknowledgement that other humans exist and do things in my environment. - - this is what i realized i missed from running my own clumsy blog scripts. i - had ways to chat, mail, and collaborate on text-based projects through the - terminal, but nothing that served as a central hub for journal-writing. - - i didn't think of myself as a strong programmer or a skilled developer, but i - had a few ideas that i thought i could try out. on april 29th, 2016, i put - out a general call in irc for people to run ~endorphant/bin/ttbp; ~sl2c - confirmed that it worked. on may 2nd, 2016, i opened it up again, and others - jumped in; ~sanqui, ~karlen, ~varscite, ~vilmibm, ~insom, ~marcus, ~nossidge, - ~jumblesale, ~krowbar. others trickled in; people sent me crash reports, - wrote to me about mysterious behaviors, lamented about broken settings when i - pushed code updates, shared with me how this fulfilled their nostalgia for an - experience that i personally never had, complained about lacking features - they wanted, yelled with delight about the interface, filled it with feelings - they didn't know how to express. - - it's now december 4th, 2016, and there are 42 users on ttbp. some of them - have never posted, many of them i've never spoken to. there are 581 entries, - which is an average of almost 14 entries per user, and a little over two and - a half entries per day. it now takes 11 seconds to load the global feed - because i implemented it sloppily, thinking i'd handle scaling issues later. - - i've loved every second of this. i'm humbled and pleased and a little - terrified at the trust and appreciation and responsibility that's been given - to me in the past seven months. - -the backend: -lessons: -future work: From 222e6e9d595d016ef43a3b8bfe4925b4de0624cd Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Wed, 28 Feb 2018 12:23:34 -0500 Subject: [PATCH 3/6] adding menu option for changing nopub default --- ttbp/ttbp.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 54605a1..896bc99 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -474,6 +474,13 @@ def setup(): save_settings() return setup() + #nopub toggling + elif settingList[int(choice)] == "nopub": + SETTINGS.update({"nopub": toggle_pub_default()}) + redraw("posting default set to {nopub}".format(nopub=SETTINGS.get("nopub"))) + save_settings() + return setup() + input("\nyou're all good to go, {friend}! hit to continue.\n\n".format(friend=chatter.say("friend"))) redraw() @@ -985,6 +992,46 @@ your changes by exiting without saving. ## misc helpers +def toggle_pub_default(): + """setup helper for setting default publish privacy (does not apply + retroactively). """ + + if SETTINGS.get("nopub", False) is True: + (nopub, will) = ("(nopub)", "won't") + else: + (nopub, will) = ("public", "will") + + if SETTINGS.get("publishing", False) is True: + publishing = "" + else: + publishing = """\ +since you're currently not publishing your posts to html/gopher, this setting +won't affect the visibility of your posts. however, the option is still here if +you'd like to change it. +""" + + print(""" + +DEFAULT POST PRIVACY + +your entries are set to automatically post as {nopub}. this means they {will} be +posted to your world-visible pages at first (which you can always change after +the fact.) + +this setting only affects subsequent posts; it does not apply retroactively. + +{publishing}""".format(nopub=nopub, will=will, publishing=publishing)) + + ans = util.input_yn("""\ +would you like to change this behavior? + +please enter""") + + if ans: + return not SETTINGS.get("nopub") + else: + return SETTINGS.get("nopub") + def toggle_rainbows(): """setup helper for rainbow toggling """ From 89a53336accf3a4f99f6c2d6d3b6c51b88bce365 Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Wed, 28 Feb 2018 13:16:51 -0500 Subject: [PATCH 4/6] entry saving respects nopub setting --- ttbp/core.py | 95 +++++++++++++++++++++++++++------------------------- ttbp/ttbp.py | 28 +++++++++------- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/ttbp/core.py b/ttbp/core.py index 3c358c0..7084fdd 100644 --- a/ttbp/core.py +++ b/ttbp/core.py @@ -235,57 +235,60 @@ def write_global_feed(blogList): prints to blog feed ''' - outfile = open(FEED, "w") + try: + outfile = open(FEED, "w") - ## header - outfile.write("""\ - - - - tilde.town feels engine - - - -
-

tilde.town feels engine

+ ## header + outfile.write("""\ + + + + tilde.town feels engine + + + +
+

tilde.town feels engine

-

github - repo | state - of the ttbp

-
-

 

-""") +

github + repo | state + of the ttbp

+
+

 

+ """) - ## docs - outfile.write("""\ -
""") - outfile.write(mistune.markdown(open(os.path.join(config.INSTALL_PATH, "..", "README.md"), "r").read())) - outfile.write("""\ -
""") + ## docs + outfile.write("""\ +
""") + outfile.write(mistune.markdown(open(os.path.join(config.INSTALL_PATH, "..", "README.md"), "r").read())) + outfile.write("""\ +
""") - ## feed - outfile.write("""\ -

 

-
-

live feels-sharing:

-
    """) - for blog in blogList: + ## feed + outfile.write("""\ +

     

    +
    +

    live feels-sharing:

    +
      """) + for blog in blogList: + outfile.write(""" +
    • """+blog+"""
    • \ + """) + + ## footer outfile.write(""" -
    • """+blog+"""
    • \ - """) +
    +
    + + + """) - ## footer - outfile.write(""" -
-
- - -""") - - outfile.close() - #subprocess.call(['chmod', 'a+w', FEED]) + outfile.close() + #subprocess.call(['chmod', 'a+w', FEED]) + except FileNotFoundError: + pass ## misc helpers @@ -309,7 +312,7 @@ def meta(entries = FILES): for filename in entries: mtime = os.path.getmtime(filename) try: - wc = subprocess.check_output(["wc","-w",filename], stderr=subprocess.STDOUT).split()[0] + wc = int(subprocess.check_output(["wc","-w",filename], stderr=subprocess.STDOUT).split()[0]) except subprocess.CalledProcessError: wc = "???" timestamp = time.strftime("%Y-%m-%d at %H:%M", time.localtime(mtime)) diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 896bc99..94f9a45 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -108,7 +108,7 @@ def menu_handler(options, prompt, pagify=10, rainbow=False, top=""): return util.list_select(options, prompt) else: - return page_helper(options, prompt, pagify, rainbow, page, total, top) + return page_helper(options, prompt, pagify, rainbow, page, int(total), top) def page_helper(options, prompt, pagify, rainbow, page, total, top): ''' @@ -126,7 +126,7 @@ def page_helper(options, prompt, pagify, rainbow, page, total, top): optPage = options[x:y] util.print_menu(optPage, SETTINGS.get("rainbows", False)) - print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down )").format(page=page+1, total=total+1) + print("\n\t( page {page} of {total}; type 'u' or 'd' to scroll up and down)".format(page=page+1, total=total+1)) ans = util.list_select(optPage, prompt) @@ -794,17 +794,21 @@ editor. left = "" - if core.publishing(): - core.load_files() - core.write("index.html") - left = "posted to {url}/index.html\n\n>".format( - url="/".join( - [config.LIVE+config.USER, - str(SETTINGS.get("publish dir"))])) + if SETTINGS.get("nopub"): + core.toggle_nopub(os.path.basename(entry)) + else: + if core.publishing(): + core.write("index.html") + left = "posted to {url}/index.html\n\n>".format( + url="/".join( + [config.LIVE+config.USER, + str(SETTINGS.get("publish dir"))])) - if SETTINGS.get('gopher'): - gopher.publish_gopher('feels', core.get_files()) - left += " also posted to your ~/public_gopher!\n" + if SETTINGS.get('gopher'): + gopher.publish_gopher('feels', core.get_files()) + left += " also posted to your ~/public_gopher!\n" + + core.load_files() redraw(left + " thanks for sharing your feels!") return From 161ce39ea737d9b5f5c4691a4f5c6ad07b321b93 Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Wed, 28 Feb 2018 17:29:10 -0500 Subject: [PATCH 5/6] updated to 0.11.2 --- ttbp/config/__init__.py | 12 ++++++-- ttbp/ttbp.py | 65 +++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/ttbp/config/__init__.py b/ttbp/config/__init__.py index 942400f..495f874 100644 --- a/ttbp/config/__init__.py +++ b/ttbp/config/__init__.py @@ -82,7 +82,7 @@ ___________________________________________________________ | ____ ____ ____ _ ____ ____ _ _ ____ _ _ _ ____ | | |___ |___ |___ | [__ |___ |\ | | __ | |\ | |___ | | | |___ |___ |___ ___] |___ | \| |__] | | \| |___ | -| ver 0.11.1 (rainbows) | +| ver 0.11.2 (rainbows) | |__________________________________________________________| '''.lstrip() @@ -146,4 +146,12 @@ version 0.9.3 features: exciting * general PSA: feel free to use the github repo for bugs/feature requests: https://github.com/modgethanc/ttbp/issues""", - } + "0.11.2": """ +~[version 0.11.2 update]~ + + * added a new option to allow setting entries to default to either public or + non-public on posting; this option only really makes sense if you're + already publishing to html/gopher, but is available either way! + + you can find this option under 'settings' as 'post as nopub'.""" +} diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 94f9a45..ebaea39 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -50,7 +50,7 @@ from . import chatter from . import gopher from . import util -__version__ = "0.11.1" +__version__ = "0.11.2" __author__ = "endorphant to explore your feels.\n\n") @@ -327,23 +329,14 @@ def gen_header(): """ return header -def valid_setup(): +def valid_setup(load_settings): ''' Checks to see if user has a valid ttbp environment. ''' - global SETTINGS - - if not os.path.isfile(config.TTBPRC): + if not load_settings: return False - try: - SETTINGS = json.load(open(config.TTBPRC)) - except ValueError: - return False - - core.load(SETTINGS) - for option in iter(DEFAULT_SETTINGS): if option != "publish dir" and SETTINGS.get(option, None) is None: return False @@ -362,6 +355,24 @@ def valid_setup(): return True +def load_user_settings(): + """attempts to load user's ttbprc; returns settings dict if valie, otherwise + returns false""" + + global SETTINGS + + if not os.path.isfile(config.TTBPRC): + return False + + try: + SETTINGS = json.load(open(config.TTBPRC)) + except ValueError: + return False + + core.load(SETTINGS) + + return SETTINGS + def setup_repair(): ''' setup repair function @@ -381,7 +392,8 @@ def setup_repair(): "publishing": select_publishing, "publish dir": select_publish_dir, "gopher": gopher.select_gopher, - "rainbows": toggle_rainbows + "rainbows": toggle_rainbows, + "post as nopub": toggle_pub_default } for option in iter(settings_map): @@ -475,9 +487,9 @@ def setup(): return setup() #nopub toggling - elif settingList[int(choice)] == "nopub": - SETTINGS.update({"nopub": toggle_pub_default()}) - redraw("posting default set to {nopub}".format(nopub=SETTINGS.get("nopub"))) + elif settingList[int(choice)] == "post as nopub": + SETTINGS.update({"post as nopub": toggle_pub_default()}) + redraw("posting default set to {nopub}".format(nopub=SETTINGS.get("post as nopub"))) save_settings() return setup() @@ -794,7 +806,7 @@ editor. left = "" - if SETTINGS.get("nopub"): + if SETTINGS.get("post as nopub"): core.toggle_nopub(os.path.basename(entry)) else: if core.publishing(): @@ -1000,7 +1012,7 @@ def toggle_pub_default(): """setup helper for setting default publish privacy (does not apply retroactively). """ - if SETTINGS.get("nopub", False) is True: + if SETTINGS.get("post as nopub", False) is True: (nopub, will) = ("(nopub)", "won't") else: (nopub, will) = ("public", "will") @@ -1032,9 +1044,9 @@ would you like to change this behavior? please enter""") if ans: - return not SETTINGS.get("nopub") + return not SETTINGS.get("post as nopub") else: - return SETTINGS.get("nopub") + return SETTINGS.get("post as nopub") def toggle_rainbows(): """setup helper for rainbow toggling @@ -1296,7 +1308,6 @@ def update_user_version(): ttbprc.close() # from earlier than 0.10.1 - if y < 10: # select gopher print("[ NEW FEATURE ]") @@ -1318,6 +1329,12 @@ def update_user_version(): print("[ NEW FEATURE ]") SETTINGS.update({"rainbows": toggle_rainbows()}) + if z < 2: + # set default option for 0.11.2 + # print("default nopub: false") + SETTINGS.update({"post as nopub": False}) + save_settings() + print(""" you're all good to go, """+chatter.say("friend")+"""! please contact ~endorphant if something strange happened to you during this update. @@ -1335,6 +1352,10 @@ something strange happened to you during this update. # version 0.11.1 patch notes print(config.UPDATES["0.11.1"]) + if y < 11 or z < 2: + # version 0.11.2 patch notes + print(config.UPDATES["0.11.2"]) + confirm = "" while confirm not in ("x", "", "X", ""): From ed41a323fdf60675924cbff58ad32e3b1e1eba34 Mon Sep 17 00:00:00 2001 From: endorphant Date: Wed, 28 Feb 2018 17:31:31 -0500 Subject: [PATCH 6/6] updating setup file --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 227ebe3..906c91d 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup( name='ttbp', - version='0.10.2', + version='0.11.2', description='command line social blogging tool used on tilde.town', url='https://github.com/modgethanc/ttbp', author='~endorphant', @@ -20,6 +20,7 @@ setup( 'inflect==0.2.5', 'mistune==0.8.1', 'colorama==0.3.9', + 'six' ], include_package_data = True, entry_points = {