Use DBEntry in redmash to get rid of all this column junk.

master
Ethan Dalool 2020-01-05 20:40:52 -08:00
parent f2f1db6bc9
commit 20c827566f
1 changed files with 15 additions and 12 deletions

View File

@ -122,33 +122,36 @@ def redmash_worker(
do_timestamp = '{timestamp}' in line_format do_timestamp = '{timestamp}' in line_format
for item in common.fetchgenerator(cur): for submission in common.fetchgenerator(cur):
submission = tsdb.DBEntry(submission)
if do_timestamp: if do_timestamp:
timestamp = int(item[tsdb.SQL_SUBMISSION['created']]) timestamp = int(submission.created)
timestamp = datetime.datetime.utcfromtimestamp(timestamp) timestamp = datetime.datetime.utcfromtimestamp(timestamp)
timestamp = timestamp.strftime(TIMESTAMP_FORMAT) timestamp = timestamp.strftime(TIMESTAMP_FORMAT)
else: else:
timestamp = '' timestamp = ''
short_link = 'https://redd.it/%s' % item[tsdb.SQL_SUBMISSION['idstr']][3:] short_link = 'https://redd.it/%s' % item.idstr[3:]
author = item[tsdb.SQL_SUBMISSION['author']] author = item.author
if author.lower() == '[deleted]': if author.lower() == '[deleted]':
author_link = '#' author_link = '#'
else: else:
author_link = 'https://reddit.com/u/%s' % author author_link = 'https://reddit.com/u/%s' % author
line = line_format.format( line = line_format.format(
author=author, author=author,
authorlink=author_link, authorlink=author_link,
flaircss=item[tsdb.SQL_SUBMISSION['flair_css_class']] or '', flaircss=submission.flair_css_class or '',
flairtext=item[tsdb.SQL_SUBMISSION['flair_text']] or '', flairtext=submission.flair_text or '',
id=item[tsdb.SQL_SUBMISSION['idstr']], id=submission.idstr,
numcomments=item[tsdb.SQL_SUBMISSION['num_comments']], numcomments=submission.num_comments,
score=item[tsdb.SQL_SUBMISSION['score']], score=submission.score,
link=short_link, link=short_link,
subreddit=item[tsdb.SQL_SUBMISSION['subreddit']], subreddit=submission.subreddit,
timestamp=timestamp, timestamp=timestamp,
title=item[tsdb.SQL_SUBMISSION['title']].replace('\n', ' '), title=submission.title.replace('\n', ' '),
url=item[tsdb.SQL_SUBMISSION['url']] or short_link, url=submission.url or short_link,
) )
line += '\n' line += '\n'
mash_handle.write(line) mash_handle.write(line)