Rename redmash.py -> index.py.

master
Ethan Dalool 2020-01-27 18:45:36 -08:00
parent 744dadd3ee
commit 2022db2b0c
3 changed files with 40 additions and 39 deletions

View File

@ -32,7 +32,7 @@ Commands for collecting:
Commands for processing: Commands for processing:
{offline_reading} {offline_reading}
{redmash} {index}
{breakdown} {breakdown}
{mergedb} {mergedb}
@ -168,12 +168,12 @@ offline_reading:
Otherwise render every submission in the database. Otherwise render every submission in the database.
''', ''',
'redmash': ''' 'index': '''
redmash: index:
Dump submission listings to a plaintext or HTML file. Dump submission listings to a plaintext or HTML file.
> timesearch.py redmash -r subredditname <flags> > timesearch.py index -r subredditname <flags>
> timesearch.py redmash -u username <flags> > timesearch.py index -u username <flags>
flags: flags:
-r "test" | --subreddit "test": -r "test" | --subreddit "test":
@ -219,16 +219,16 @@ redmash:
Perform a mash sorted by flair. Perform a mash sorted by flair.
examples: examples:
`timesearch redmash -r botwatch --date` `timesearch index -r botwatch --date`
does only the date file. does only the date file.
`timesearch redmash -r botwatch --score --title` `timesearch index -r botwatch --score --title`
does both the score and title files. 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. only shows submissions with >= 50 points.
`timesearch redmash -r botwatch --all` `timesearch index -r botwatch --all`
performs all of the different mashes. performs all of the different mashes.
''', ''',
@ -268,6 +268,7 @@ get_submissions:
OLD_COMMAND_ALIASES = { OLD_COMMAND_ALIASES = {
'timesearch': 'get_submissions', 'timesearch': 'get_submissions',
'commentaugment': 'get_comments', 'commentaugment': 'get_comments',
'redmash': 'index',
} }
@ -326,9 +327,9 @@ def offline_reading_gateway(args):
from . import offline_reading from . import offline_reading
offline_reading.offline_reading_argparse(args) offline_reading.offline_reading_argparse(args)
def redmash_gateway(args): def index_gateway(args):
from . import redmash from . import index
redmash.redmash_argparse(args) index.index_argparse(args)
def get_submissions_gateway(args): def get_submissions_gateway(args):
from . import get_submissions 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.add_argument('-u', '--user', dest='username', default=None)
p_offline_reading.set_defaults(func=offline_reading_gateway) p_offline_reading.set_defaults(func=offline_reading_gateway)
p_redmash = subparsers.add_parser('redmash') p_index = subparsers.add_parser('index', aliases=['redmash'])
p_redmash.add_argument('--all', dest='do_all', action='store_true') p_index.add_argument('--all', dest='do_all', action='store_true')
p_redmash.add_argument('--author', dest='do_author', action='store_true') p_index.add_argument('--author', dest='do_author', action='store_true')
p_redmash.add_argument('--date', dest='do_date', action='store_true') p_index.add_argument('--date', dest='do_date', action='store_true')
p_redmash.add_argument('--flair', dest='do_flair', action='store_true') p_index.add_argument('--flair', dest='do_flair', action='store_true')
p_redmash.add_argument('--html', dest='html', action='store_true') p_index.add_argument('--html', dest='html', action='store_true')
p_redmash.add_argument('--score', dest='do_score', action='store_true') p_index.add_argument('--score', dest='do_score', action='store_true')
p_redmash.add_argument('--sub', dest='do_subreddit', action='store_true') p_index.add_argument('--sub', dest='do_subreddit', action='store_true')
p_redmash.add_argument('--title', dest='do_title', action='store_true') p_index.add_argument('--title', dest='do_title', action='store_true')
p_redmash.add_argument('--offline', dest='offline', action='store_true') p_index.add_argument('--offline', dest='offline', action='store_true')
p_redmash.add_argument('-r', '--subreddit', dest='subreddit', default=None) p_index.add_argument('-r', '--subreddit', dest='subreddit', default=None)
p_redmash.add_argument('-st', '--score_threshold', dest='score_threshold', default=0) p_index.add_argument('-st', '--score_threshold', dest='score_threshold', default=0)
p_redmash.add_argument('-u', '--user', dest='username', default=None) p_index.add_argument('-u', '--user', dest='username', default=None)
p_redmash.set_defaults(func=redmash_gateway) p_index.set_defaults(func=index_gateway)
p_get_submissions = subparsers.add_parser('get_submissions', aliases=['timesearch']) p_get_submissions = subparsers.add_parser('get_submissions', aliases=['timesearch'])
p_get_submissions.add_argument('-l', '--lower', dest='lower', default='update') p_get_submissions.add_argument('-l', '--lower', dest='lower', default='update')

View File

@ -40,7 +40,7 @@ HTML_FOOTER = '''
''' '''
def redmash( def index(
subreddit=None, subreddit=None,
username=None, username=None,
do_all=False, do_all=False,
@ -67,35 +67,35 @@ def redmash(
if do_all or do_date: if do_all or do_date:
print('Writing time file') 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: if do_all or do_title:
print('Writing title file') 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: if do_all or do_score:
print('Writing score file') 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): if not username and (do_all or do_author):
print('Writing author file') 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): if username and (do_all or do_subreddit):
print('Writing subreddit file') 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: if do_all or do_flair:
print('Writing flair file') print('Writing flair file')
# Items with flair come before items without. Each group is sorted by time separately. # Items with flair come before items without. Each group is sorted by time separately.
orderby = 'flair_text IS NULL ASC, created ASC' 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: if not wrote:
raise Exception('No sorts selected! Read the docstring') raise Exception('No sorts selected! Read the docstring')
print('Done.') print('Done.')
def redmash_worker( def index_worker(
database, database,
suffix, suffix,
orderby, orderby,
@ -108,12 +108,12 @@ def redmash_worker(
statement = statement.format(threshold=score_threshold, order=orderby) statement = statement.format(threshold=score_threshold, order=orderby)
cur.execute(statement) 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' extension = '.html' if html else '.txt'
mash_basename = database.filepath.replace_extension('').basename mash_basename = database.filepath.replace_extension('').basename
mash_basename += suffix + extension 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') mash_handle = open(mash_filepath.absolute_path, 'w', encoding='UTF-8')
if html: if html:
@ -168,8 +168,8 @@ def redmash_worker(
print('Wrote', mash_filepath.relative_path) print('Wrote', mash_filepath.relative_path)
return mash_filepath return mash_filepath
def redmash_argparse(args): def index_argparse(args):
return redmash( return index(
subreddit=args.subreddit, subreddit=args.subreddit,
username=args.username, username=args.username,
do_all=args.do_all, do_all=args.do_all,

View File

@ -176,7 +176,7 @@ class TSDB:
self.breakdown_dir = self.filepath.parent.with_child('breakdown') self.breakdown_dir = self.filepath.parent.with_child('breakdown')
self.offline_reading_dir = self.filepath.parent.with_child('offline_reading') 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.styles_dir = self.filepath.parent.with_child('styles')
self.wiki_dir = self.filepath.parent.with_child('wiki') self.wiki_dir = self.filepath.parent.with_child('wiki')