Revert "Use .format() instead of regular expression"

This reverts commit 8e82252832.
This commit is contained in:
Ali Parlakci 2021-03-30 10:43:32 +03:00
parent 0fe28deee9
commit f06e8f3ac4

View File

@ -27,15 +27,20 @@ class FileNameFormatter:
@staticmethod
def _format_name(submission: praw.models.Submission, format_string: str) -> str:
submission_attributes = {
'TITLE': submission.title,
'SUBREDDIT': submission.subreddit.display_name,
'REDDITOR': submission.author.name if submission.author else 'DELETED',
'POSTID': submission.id,
'UPVOTES': submission.score,
'FLAIR': submission.link_flair_text,
'DATE': submission.created_utc
'title': submission.title,
'subreddit': submission.subreddit.display_name,
'redditor': submission.author.name if submission.author else 'DELETED',
'postid': submission.id,
'upvotes': submission.score,
'flair': submission.link_flair_text,
'date': submission.created_utc
}
result = format_string.format(**submission_attributes)
result = format_string
for key in submission_attributes.keys():
if re.search(r'(?i).*{{{}}}.*'.format(key), result):
result = re.sub(r'(?i){{{}}}'.format(key), str(submission_attributes.get(key, 'unknown')), result)
logger.log(9, f'Found key string {key} in name')
result = result.replace('/', '')
if platform.system() == 'Windows':