From 2022db2b0cee3c342934f9b083f957b3dfc9b006 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 27 Jan 2020 18:45:36 -0800 Subject: [PATCH] Rename redmash.py -> index.py. --- timesearch_modules/__init__.py | 53 +++++++++++---------- timesearch_modules/{redmash.py => index.py} | 24 +++++----- timesearch_modules/tsdb.py | 2 +- 3 files changed, 40 insertions(+), 39 deletions(-) rename timesearch_modules/{redmash.py => index.py} (85%) diff --git a/timesearch_modules/__init__.py b/timesearch_modules/__init__.py index ac7162f..bcc9170 100644 --- a/timesearch_modules/__init__.py +++ b/timesearch_modules/__init__.py @@ -32,7 +32,7 @@ Commands for collecting: Commands for processing: {offline_reading} -{redmash} +{index} {breakdown} {mergedb} @@ -168,12 +168,12 @@ offline_reading: Otherwise render every submission in the database. ''', - 'redmash': ''' -redmash: + 'index': ''' +index: Dump submission listings to a plaintext or HTML file. - > timesearch.py redmash -r subredditname - > timesearch.py redmash -u username + > timesearch.py index -r subredditname + > timesearch.py index -u username flags: -r "test" | --subreddit "test": @@ -219,16 +219,16 @@ redmash: Perform a mash sorted by flair. examples: - `timesearch redmash -r botwatch --date` + `timesearch index -r botwatch --date` does only the date file. - `timesearch redmash -r botwatch --score --title` + `timesearch index -r botwatch --score --title` does both the score and title files. - `timesearch redmash -r botwatch --score --score_threshold 50` + `timesearch index -r botwatch --score --score_threshold 50` only shows submissions with >= 50 points. - `timesearch redmash -r botwatch --all` + `timesearch index -r botwatch --all` performs all of the different mashes. ''', @@ -268,6 +268,7 @@ get_submissions: OLD_COMMAND_ALIASES = { 'timesearch': 'get_submissions', 'commentaugment': 'get_comments', + 'redmash': 'index', } @@ -326,9 +327,9 @@ def offline_reading_gateway(args): from . import offline_reading offline_reading.offline_reading_argparse(args) -def redmash_gateway(args): - from . import redmash - redmash.redmash_argparse(args) +def index_gateway(args): + from . import index + index.index_argparse(args) def get_submissions_gateway(args): from . import get_submissions @@ -384,20 +385,20 @@ p_offline_reading.add_argument('-s', '--specific', dest='specific_submission', d p_offline_reading.add_argument('-u', '--user', dest='username', default=None) p_offline_reading.set_defaults(func=offline_reading_gateway) -p_redmash = subparsers.add_parser('redmash') -p_redmash.add_argument('--all', dest='do_all', action='store_true') -p_redmash.add_argument('--author', dest='do_author', action='store_true') -p_redmash.add_argument('--date', dest='do_date', action='store_true') -p_redmash.add_argument('--flair', dest='do_flair', action='store_true') -p_redmash.add_argument('--html', dest='html', action='store_true') -p_redmash.add_argument('--score', dest='do_score', action='store_true') -p_redmash.add_argument('--sub', dest='do_subreddit', action='store_true') -p_redmash.add_argument('--title', dest='do_title', action='store_true') -p_redmash.add_argument('--offline', dest='offline', action='store_true') -p_redmash.add_argument('-r', '--subreddit', dest='subreddit', default=None) -p_redmash.add_argument('-st', '--score_threshold', dest='score_threshold', default=0) -p_redmash.add_argument('-u', '--user', dest='username', default=None) -p_redmash.set_defaults(func=redmash_gateway) +p_index = subparsers.add_parser('index', aliases=['redmash']) +p_index.add_argument('--all', dest='do_all', action='store_true') +p_index.add_argument('--author', dest='do_author', action='store_true') +p_index.add_argument('--date', dest='do_date', action='store_true') +p_index.add_argument('--flair', dest='do_flair', action='store_true') +p_index.add_argument('--html', dest='html', action='store_true') +p_index.add_argument('--score', dest='do_score', action='store_true') +p_index.add_argument('--sub', dest='do_subreddit', action='store_true') +p_index.add_argument('--title', dest='do_title', action='store_true') +p_index.add_argument('--offline', dest='offline', action='store_true') +p_index.add_argument('-r', '--subreddit', dest='subreddit', default=None) +p_index.add_argument('-st', '--score_threshold', dest='score_threshold', default=0) +p_index.add_argument('-u', '--user', dest='username', default=None) +p_index.set_defaults(func=index_gateway) p_get_submissions = subparsers.add_parser('get_submissions', aliases=['timesearch']) p_get_submissions.add_argument('-l', '--lower', dest='lower', default='update') diff --git a/timesearch_modules/redmash.py b/timesearch_modules/index.py similarity index 85% rename from timesearch_modules/redmash.py rename to timesearch_modules/index.py index b7d1ec1..1d52f8b 100644 --- a/timesearch_modules/redmash.py +++ b/timesearch_modules/index.py @@ -40,7 +40,7 @@ HTML_FOOTER = ''' ''' -def redmash( +def index( subreddit=None, username=None, do_all=False, @@ -67,35 +67,35 @@ def redmash( if do_all or do_date: print('Writing time file') - wrote = redmash_worker(database, suffix='_date', orderby='created ASC', **kwargs) + wrote = index_worker(database, suffix='_date', orderby='created ASC', **kwargs) if do_all or do_title: print('Writing title file') - wrote = redmash_worker(database, suffix='_title', orderby='title ASC', **kwargs) + wrote = index_worker(database, suffix='_title', orderby='title ASC', **kwargs) if do_all or do_score: print('Writing score file') - wrote = redmash_worker(database, suffix='_score', orderby='score DESC', **kwargs) + wrote = index_worker(database, suffix='_score', orderby='score DESC', **kwargs) if not username and (do_all or do_author): print('Writing author file') - wrote = redmash_worker(database, suffix='_author', orderby='author ASC', **kwargs) + wrote = index_worker(database, suffix='_author', orderby='author ASC', **kwargs) if username and (do_all or do_subreddit): print('Writing subreddit file') - wrote = redmash_worker(database, suffix='_subreddit', orderby='subreddit ASC', **kwargs) + wrote = index_worker(database, suffix='_subreddit', orderby='subreddit ASC', **kwargs) if do_all or do_flair: print('Writing flair file') # Items with flair come before items without. Each group is sorted by time separately. orderby = 'flair_text IS NULL ASC, created ASC' - wrote = redmash_worker(database, suffix='_flair', orderby=orderby, **kwargs) + wrote = index_worker(database, suffix='_flair', orderby=orderby, **kwargs) if not wrote: raise Exception('No sorts selected! Read the docstring') print('Done.') -def redmash_worker( +def index_worker( database, suffix, orderby, @@ -108,12 +108,12 @@ def redmash_worker( statement = statement.format(threshold=score_threshold, order=orderby) cur.execute(statement) - os.makedirs(database.redmash_dir.absolute_path, exist_ok=True) + os.makedirs(database.index_dir.absolute_path, exist_ok=True) extension = '.html' if html else '.txt' mash_basename = database.filepath.replace_extension('').basename mash_basename += suffix + extension - mash_filepath = database.redmash_dir.with_child(mash_basename) + mash_filepath = database.index_dir.with_child(mash_basename) mash_handle = open(mash_filepath.absolute_path, 'w', encoding='UTF-8') if html: @@ -168,8 +168,8 @@ def redmash_worker( print('Wrote', mash_filepath.relative_path) return mash_filepath -def redmash_argparse(args): - return redmash( +def index_argparse(args): + return index( subreddit=args.subreddit, username=args.username, do_all=args.do_all, diff --git a/timesearch_modules/tsdb.py b/timesearch_modules/tsdb.py index 2c49c41..9a8f9e9 100644 --- a/timesearch_modules/tsdb.py +++ b/timesearch_modules/tsdb.py @@ -176,7 +176,7 @@ class TSDB: self.breakdown_dir = self.filepath.parent.with_child('breakdown') self.offline_reading_dir = self.filepath.parent.with_child('offline_reading') - self.redmash_dir = self.filepath.parent.with_child('redmash') + self.index_dir = self.filepath.parent.with_child('redmash') self.styles_dir = self.filepath.parent.with_child('styles') self.wiki_dir = self.filepath.parent.with_child('wiki')