Add argument --offline to redmash, points to offline_reading files.
Previously, the files generated by offline_reading were difficult to use because there was no index file and the filenames are just ids. So now, the redmash can act as an index!
This commit is contained in:
parent
20c827566f
commit
43ce535b4f
2 changed files with 20 additions and 6 deletions
|
@ -185,6 +185,12 @@ redmash:
|
||||||
--html:
|
--html:
|
||||||
Write HTML files instead of plain text.
|
Write HTML files instead of plain text.
|
||||||
|
|
||||||
|
--offline:
|
||||||
|
The links in the mash will point to the files generated by
|
||||||
|
offline_reading. That is, `../offline_reading/fullname.html` instead
|
||||||
|
of `http://redd.it/id`. This will NOT trigger offline_reading to
|
||||||
|
generate the files now, so you must run that tool separately.
|
||||||
|
|
||||||
-st 50 | --score_threshold 50:
|
-st 50 | --score_threshold 50:
|
||||||
Only mash posts with at least this many points.
|
Only mash posts with at least this many points.
|
||||||
Applies to ALL mashes!
|
Applies to ALL mashes!
|
||||||
|
@ -382,6 +388,7 @@ 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('--score', dest='do_score', action='store_true')
|
||||||
p_redmash.add_argument('--sub', dest='do_subreddit', 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('--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('-r', '--subreddit', dest='subreddit', default=None)
|
||||||
p_redmash.add_argument('-st', '--score_threshold', dest='score_threshold', default=0)
|
p_redmash.add_argument('-st', '--score_threshold', dest='score_threshold', default=0)
|
||||||
p_redmash.add_argument('-u', '--user', dest='username', default=None)
|
p_redmash.add_argument('-u', '--user', dest='username', default=None)
|
||||||
|
|
|
@ -15,7 +15,7 @@ LINE_FORMAT_HTML = '''
|
||||||
'''.replace('\n', '')
|
'''.replace('\n', '')
|
||||||
|
|
||||||
TIMESTAMP_FORMAT = '%Y %b %d'
|
TIMESTAMP_FORMAT = '%Y %b %d'
|
||||||
#The time format.
|
# The time format.
|
||||||
# "%Y %b %d" = "2016 August 10"
|
# "%Y %b %d" = "2016 August 10"
|
||||||
# See http://strftime.org/
|
# See http://strftime.org/
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ def redmash(
|
||||||
do_subreddit=False,
|
do_subreddit=False,
|
||||||
do_flair=False,
|
do_flair=False,
|
||||||
html=False,
|
html=False,
|
||||||
|
offline=False,
|
||||||
score_threshold=0,
|
score_threshold=0,
|
||||||
):
|
):
|
||||||
if not common.is_xor(subreddit, username):
|
if not common.is_xor(subreddit, username):
|
||||||
|
@ -61,7 +62,7 @@ def redmash(
|
||||||
else:
|
else:
|
||||||
database = tsdb.TSDB.for_user(username, do_create=False)
|
database = tsdb.TSDB.for_user(username, do_create=False)
|
||||||
|
|
||||||
kwargs = {'html': html, 'score_threshold': score_threshold}
|
kwargs = {'html': html, 'offline': offline, 'score_threshold': score_threshold}
|
||||||
wrote = None
|
wrote = None
|
||||||
|
|
||||||
if do_all or do_date:
|
if do_all or do_date:
|
||||||
|
@ -100,6 +101,7 @@ def redmash_worker(
|
||||||
orderby,
|
orderby,
|
||||||
score_threshold=0,
|
score_threshold=0,
|
||||||
html=False,
|
html=False,
|
||||||
|
offline=False,
|
||||||
):
|
):
|
||||||
cur = database.sql.cursor()
|
cur = database.sql.cursor()
|
||||||
statement = 'SELECT * FROM submissions WHERE score >= {threshold} ORDER BY {order}'
|
statement = 'SELECT * FROM submissions WHERE score >= {threshold} ORDER BY {order}'
|
||||||
|
@ -132,8 +134,12 @@ def redmash_worker(
|
||||||
else:
|
else:
|
||||||
timestamp = ''
|
timestamp = ''
|
||||||
|
|
||||||
short_link = 'https://redd.it/%s' % item.idstr[3:]
|
if offline:
|
||||||
author = item.author
|
link = f'../offline_reading/{submission.idstr}.html'
|
||||||
|
else:
|
||||||
|
link = f'https://redd.it/{submission.idstr[3:]}'
|
||||||
|
|
||||||
|
author = submission.author
|
||||||
if author.lower() == '[deleted]':
|
if author.lower() == '[deleted]':
|
||||||
author_link = '#'
|
author_link = '#'
|
||||||
else:
|
else:
|
||||||
|
@ -147,11 +153,11 @@ def redmash_worker(
|
||||||
id=submission.idstr,
|
id=submission.idstr,
|
||||||
numcomments=submission.num_comments,
|
numcomments=submission.num_comments,
|
||||||
score=submission.score,
|
score=submission.score,
|
||||||
link=short_link,
|
link=link,
|
||||||
subreddit=submission.subreddit,
|
subreddit=submission.subreddit,
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
title=submission.title.replace('\n', ' '),
|
title=submission.title.replace('\n', ' '),
|
||||||
url=submission.url or short_link,
|
url=submission.url or link,
|
||||||
)
|
)
|
||||||
line += '\n'
|
line += '\n'
|
||||||
mash_handle.write(line)
|
mash_handle.write(line)
|
||||||
|
@ -174,5 +180,6 @@ def redmash_argparse(args):
|
||||||
do_subreddit=args.do_subreddit,
|
do_subreddit=args.do_subreddit,
|
||||||
do_flair=args.do_flair,
|
do_flair=args.do_flair,
|
||||||
html=args.html,
|
html=args.html,
|
||||||
|
offline=args.offline,
|
||||||
score_threshold=common.int_none(args.score_threshold),
|
score_threshold=common.int_none(args.score_threshold),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue