From 95a26625ca78e138b5e97898795306a102e2241c Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Mon, 29 Jun 2020 13:09:23 +0000 Subject: [PATCH] Refactored by Sourcery --- app/__init__.py | 38 ++++++++++++++++++++++++-------------- app/handler.py | 6 +----- app/html2template.py | 3 +-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 3eefdb6..e5de4e9 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -72,17 +72,27 @@ def create_app(): debug=options.config['debug'], gzip=True, ) - app = web.Application([ - (r'/', IndexHandler), - (r'/posts', PostsHandler), - (r'/p/(.*)', PostHandler), - (r'/achive', AchiveHandler), - (r'/share', ShareHandler), - (r'/product', ProductHandler), - (r'/link', LinkHandler), - (r'/about', AboutHandler), - (r'/((js|css|image)/.*)', web.StaticFileHandler, dict(path=settings['static_path'])), - (r'/(.*\.(txt|html))', web.StaticFileHandler, dict(path=settings['static_path'])), - (r'.*', PageNotFoundHandler) - ], **settings) - return app + return web.Application( + [ + (r'/', IndexHandler), + (r'/posts', PostsHandler), + (r'/p/(.*)', PostHandler), + (r'/achive', AchiveHandler), + (r'/share', ShareHandler), + (r'/product', ProductHandler), + (r'/link', LinkHandler), + (r'/about', AboutHandler), + ( + r'/((js|css|image)/.*)', + web.StaticFileHandler, + dict(path=settings['static_path']), + ), + ( + r'/(.*\.(txt|html))', + web.StaticFileHandler, + dict(path=settings['static_path']), + ), + (r'.*', PageNotFoundHandler), + ], + **settings + ) diff --git a/app/handler.py b/app/handler.py index 2518a00..b855ba1 100644 --- a/app/handler.py +++ b/app/handler.py @@ -39,11 +39,7 @@ def get(self): class PostHandler(BaseHandler): def get(self, url): - found_post = False - for post in options.config['posts']: - if url == post['id']: - found_post = True - break + found_post = any(url == post['id'] for post in options.config['posts']) if found_post: self.render('post/' + post['title'] + '.html', timestamp=post['timestamp']) diff --git a/app/html2template.py b/app/html2template.py index 41d21de..6ff356c 100644 --- a/app/html2template.py +++ b/app/html2template.py @@ -47,8 +47,7 @@ def html2template(): ) for post_file_name in new_posts: if '.html' in post_file_name: - post = {} - post['title'] = post_file_name.replace('.html', '') + post = {'title': post_file_name.replace('.html', '')} post['id'] = post['title'].replace(' ', '') with open( os.path.join(