<commit_before>"""
This module contains gopher-related stuff.
"""
import getpass
import os

from . import util

GOPHER_PROMPT = """
Would you like to publish your feels to gopher?

gopher is a pre-web technology that is text-oriented and primarily used to
share folders of your files with the world.

If you don't know what it is or don't want it that is totally ok!

You can always change this later.""".lstrip()

GOPHERMAP_HEADER = """
 welcome to {user}'s feels on gopher.

     .::                     .::
   .:                        .::
 .:.: .:   .::       .::     .:: .::::
   .::   .:   .::  .:   .::  .::.::
   .::  .::::: .::.::::: .:: .::  .:::
   .::  .:        .:         .::    .::
   .::    .::::     .::::   .:::.:: .::

 this file was created on their behalf by ttbp.

"""


def select_gopher():
    return util.input_yn(GOPHER_PROMPT)


def publish_gopher(gopher_path, entry_filenames):
    """This function (re)generates a user's list of feels posts in their gopher
    directory and their gophermap."""
    entry_filenames = entry_filenames[:]  # force a copy since this might be shared state in core.py
    entry_filenames.reverse()
    ttbp_gopher = os.path.join(
        os.path.expanduser('~/public_gopher'),
        gopher_path)

    if not os.path.isdir(ttbp_gopher):
        print('\n\tERROR: something is wrong. your gopher directory is missing. re-enable gopher publishing.')
        return

    with open(os.path.join(ttbp_gopher, 'gophermap'), 'w') as gophermap: 
        gophermap.write(GOPHERMAP_HEADER.format(
                        user=getpass.getuser()))
        for entry_filename in entry_filenames:
            filename = os.path.basename(entry_filename)

            with open(os.path.join(ttbp_gopher, filename), 'w') as gopher_entry:
                with open(entry_filename, 'r') as source_entry:
                    gopher_entry.write(source_entry.read())
            gophermap.write('0{file_label}\t{filename}'.format(
                file_label=os.path.basename(entry_filename),<commit_msg>sprucing up gophermap printing<commit_after>"""
This module contains gopher-related stuff.
"""
import getpass
import os
import time

from . import util
from .core import parse_date

GOPHER_PROMPT = """
Would you like to publish your feels to gopher?

gopher is a pre-web technology that is text-oriented and primarily used to
share folders of your files with the world.

If you don't know what it is or don't want it that is totally ok!

You can always change this later.""".lstrip()

GOPHERMAP_HEADER = """
 welcome to {user}'s feels on gopher.

     .::                     .::
   .:                        .::
 .:.: .:   .::       .::     .:: .::::
   .::   .:   .::  .:   .::  .::.::
   .::  .::::: .::.::::: .:: .::  .:::
   .::  .:        .:         .::    .::
   .::    .::::     .::::   .:::.:: .::

 this file was created on their behalf by ttbp.

0(about ttbp)\t/~endorphant/ttbp.txt\ttilde.town\t70
1(back to user's home)\t/~{user}

 entries:

"""


def select_gopher():
    return util.input_yn(GOPHER_PROMPT)


def publish_gopher(gopher_path, entry_filenames):
    """This function (re)generates a user's list of feels posts in their gopher
    directory and their gophermap."""
    entry_filenames = entry_filenames[:]  # force a copy since this might be shared state in core.py
    #entry_filenames.reverse()
    ttbp_gopher = os.path.join(
        os.path.expanduser('~/public_gopher'),
        gopher_path)

    if not os.path.isdir(ttbp_gopher):
        print('\n\tERROR: something is wrong. your gopher directory is missing. re-enable gopher publishing.')
        return

    with open(os.path.join(ttbp_gopher, 'gophermap'), 'w') as gophermap:
        gophermap.write(GOPHERMAP_HEADER.format(
                        user=getpass.getuser()))
        for entry_filename in entry_filenames:
            filename = os.path.basename(entry_filename)

            with open(os.path.join(ttbp_gopher, filename), 'w') as gopher_entry:
                with open(entry_filename, 'r') as source_entry:
                    gopher_entry.write(source_entry.read())

            #label = time.strftime("%Y-%m-%d at %H:%M", time.localtime(os.path.getmtime(entry_filename)))
            label = "-".join(parse_date(entry_filename))
            gophermap.write('0{file_label}\t{filename}\n'.format(
                file_label=label,
{'fraction_non_alphanumeric': 0.14132174708438144, 'fraction_numerical': 0.001372055796935742, 'mean_word_length': 2.3802163833075736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '602629', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1382, 'n_words': 352}