Skip to content

Commit e5ea8c0

Browse files
committed
Refactoring code to satisfy some pylint messages
1 parent e1496e7 commit e5ea8c0

File tree

7 files changed

+22
-30
lines changed

7 files changed

+22
-30
lines changed

reddit_utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def create_app(test_config=None):
2727
# load the test config if passed in
2828
app.config.from_mapping(test_config)
2929

30-
LOGGER_CONFIG = os.path.join(app.root_path, 'files', 'logging_config.yaml')
30+
logger_config = os.path.join(app.root_path, 'files', 'logging_config.yaml')
3131

32-
with open(LOGGER_CONFIG) as fid:
32+
with open(logger_config) as fid:
3333

3434
try:
3535
global_config = yaml.safe_load(fid)

reddit_utils/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def login():
2222
token['client_secret'] = request.form['clientsecret']
2323
token['username'] = request.form['username']
2424
token['password'] = request.form['password']
25-
25+
2626
result = get_reddit_object(token)
2727

2828
if result['status'] == 'error':

reddit_utils/features/list_subreddits.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
from pprint import pprint as pp
66

77
from flask import (
8-
Blueprint, flash, g, redirect, render_template, request, url_for
8+
Blueprint, flash, g, render_template, request
99
)
1010

1111
from ..auth import api_access_required
1212
from ..reddit import get_reddit_object
13-
from .search import perform_search, check_form
1413

1514
bp = Blueprint('list_subreddits', __name__)
1615

@@ -50,14 +49,10 @@ def get_subs(token, get_latest, sort_by, sort_reverse):
5049

5150
if result['status'] == 'error':
5251
return result
53-
else:
54-
reddit = result['data']
5552

53+
reddit = result['data']
5654
results = []
5755

58-
print('fetching items: ')
59-
print('-'*200)
60-
6156
for subreddit in reddit.user.subreddits(limit=None):
6257

6358
subreddit.id # trigger loading
@@ -112,10 +107,7 @@ def check_form(form):
112107
else:
113108
options['sort_by'] = 'subscribers'
114109

115-
if 'sort_order' in form and form['sort_order'] == 'desc':
116-
options['sort_reverse'] = True
117-
else:
118-
options['sort_reverse'] = False
110+
options['sort_reverse'] = 'sort_order' in form and form['sort_order'] == 'desc'
119111

120112
# if we are not getting the latest post, we can't sort by the time of the last post
121113
if not options['get_latest'] and form['sort_by'] == 'last_post':

reddit_utils/features/search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11

2-
import json
32
import logging
43

54
import pprint
65
from pprint import pprint as pp
76

8-
import praw
97
from praw.models import Submission
108
from praw.models import Comment
119

@@ -21,8 +19,8 @@ def perform_search(search_options, token):
2119

2220
if result['status'] == 'error':
2321
return result
24-
else:
25-
reddit = result['data']
22+
23+
reddit = result['data']
2624

2725
results = user_saved(reddit, **search_options)
2826
results = list(results) if results else []
@@ -129,6 +127,8 @@ def query_in_str(queries, string):
129127
if query in string:
130128
return True
131129

130+
return False
131+
132132

133133

134134
def item_in_subreddit(item, subreddits):

reddit_utils/features/search_saved.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pprint
44

55
from flask import (
6-
Blueprint, flash, g, redirect, render_template, request, url_for
6+
Blueprint, flash, g, render_template, request
77
)
88

99
from ..auth import api_access_required

reddit_utils/reddit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
def get_reddit_object(token):
1212

1313
try:
14-
15-
reddit = praw.Reddit(user_agent= 'Script that searches saved posts',
14+
15+
reddit = praw.Reddit(user_agent='reddit_utils web app by Roman Kuleshov',
1616
client_id=token['client_id'],
1717
client_secret=token['client_secret'],
1818
username=token['username'],
@@ -29,4 +29,4 @@ def get_reddit_object(token):
2929
return {'status': 'error', 'data': 'Error: ResponseException: ' + str(err)}
3030

3131
except Exception as err:
32-
return {'status': 'error', 'data': 'Unexpected Error: ' + str(err)}
32+
return {'status': 'error', 'data': 'Unexpected Error: ' + str(err)}

reddit_utils/util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
class MakeFileHandler(logging.FileHandler):
1111

12-
# https://stackoverflow.com/questions/20666764/python-logging-how-to-ensure-logfile-directory-is-created
13-
# https://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python/600612#600612
12+
# https://stackoverflow.com/questions/20666764/python-logging-how-to-ensure-logfile-directory-is-created
13+
# https://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python/600612#600612
1414

15-
def __init__(self, filename, mode='a', encoding=None, delay=0):
15+
def __init__(self, filename, mode='a', encoding=None, delay=0):
1616
pathlib.Path(os.path.dirname(filename)).mkdir(parents=True, exist_ok=True)
1717
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
1818

@@ -25,15 +25,15 @@ def format_full_date(value):
2525

2626

2727
def format_timestamp(value, only_distance=False):
28-
28+
2929
return arrow.get(value).humanize(only_distance=only_distance)
3030

3131

3232

3333
def format_karma_score(karma):
3434

35-
if karma > 1000:
36-
karma = karma / 1000
37-
karma = str(int(karma)) + 'k'
35+
if karma > 1000:
36+
karma = karma / 1000
37+
karma = str(int(karma)) + 'k'
3838

39-
return karma
39+
return karma

0 commit comments

Comments
 (0)