Skip to content

Commit

Permalink
Tidy up articles and config files slightly from pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiefdhurst committed Aug 12, 2024
1 parent 58ecaa5 commit 278952b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions blog/articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ def __init__(self, directory, filename):

self.filename = filename
try:
with open(directory + filename, encoding='UTF8') as file:
with open(directory + filename, encoding='UTF-8') as file:
self.contents = markdown(file.read(), extensions=['fenced_code'])
except FileNotFoundError as fnfe:
raise ArticleNotFoundException(f"Could not find article file {filename}") from fnfe
raise ArticleNotFoundException(f'Could not find article file {filename}') from fnfe

def get_contents(self):
return self.contents

def get_content_only(self):
title = self.find_title.search(self.contents)
summary = self.find_summary.search(self.contents)
contents = self.contents.replace(title.group(0), '')
contents = self.contents.replace(title.group(0), '')
if summary:
return contents.replace(summary.group(0), '')
return contents
Expand All @@ -34,7 +34,8 @@ def get_date(self):
find_date = re.compile(r'^(\d{4}-\d{2}-\d{2})_')
date = find_date.match(self.filename)
if not date:
raise InvalidDateForArticleException(f"Could not parse date for article {self.filename}")
raise InvalidDateForArticleException(
f'Could not parse date for article {self.filename}')
return datetime.datetime.strptime(date.group(1), '%Y-%m-%d')

def get_image(self):
Expand All @@ -55,7 +56,8 @@ def get_summary(self):
def get_title(self):
title = self.find_title.search(self.contents)
if not title:
raise InvalidTitleForArticleException(f"Could not parse title for article {self.filename}")
raise InvalidTitleForArticleException(
f'Could not parse title for article {self.filename}')
return title.group(1)


Expand All @@ -70,7 +72,6 @@ def __parse_articles(directory, files):
def get_article(directory, file):
return Article(directory, file + '.md')


def get_paginated_articles(directory, page=1, per_page=10):
files = [f for f in listdir(directory) if isfile(join(directory, f))]
files.sort()
Expand Down
2 changes: 1 addition & 1 deletion blog/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import environ
from os import environ

ARTICLES_DIR = environ.get('ARTICLES_DIR', default='articles/')
DIST_DIR = environ.get('DIST_DIR', default='dist/')
Expand Down

0 comments on commit 278952b

Please sign in to comment.