Skip to content

Commit bfc38b0

Browse files
authored
OD-1731: Misc. cleanup (#37)
* OD-1731: Remove unused imports * OD-1731: Fix f-strings without placeholders * OD-1731: Don't store exceptions if we're not going to use them
1 parent f4258ed commit bfc38b0

13 files changed

Lines changed: 17 additions & 31 deletions

File tree

efiction/chapters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def load_chapter_text_into_db(self, chapter_paths: List[dict]):
9696
# check if encoding is valid
9797
''.encode(encoding_text)
9898
encoding = encoding_text
99-
except:
99+
except LookupError:
100100
print(f"{encoding_text} is not a valid encoding, try again")
101101
for old_chapter in old_chapters:
102102
chapid = old_chapter['chapid']

efiction/metadata.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import re
32
from configparser import ConfigParser
43
from logging import Logger
@@ -152,7 +151,7 @@ def _convert_story_tags(self, old_story):
152151
def _convert_tags_join(self, new_story, tags, sql=None):
153152
# Support using non-default sql connection for multithreaded workloads
154153
sql = self.sql if sql is None else sql
155-
full_query = f"INSERT INTO item_tags (item_id, item_type, tag_id) VALUES "
154+
full_query = "INSERT INTO item_tags (item_id, item_type, tag_id) VALUES "
156155
tag_query = []
157156
for tag_list in tags.values():
158157
for tag in tag_list:
@@ -176,7 +175,7 @@ def fetch_coauthors(self, new_story, sql=None):
176175
# get a dict of coauthor IDs for the story
177176
try:
178177
authors = sql.execute_and_fetchall(self.working_original, full_query)
179-
except Exception as e:
178+
except Exception:
180179
authors = None
181180
self.logger.info("No coauthors table...")
182181
# We only try to operate on this result if it is not None
@@ -219,12 +218,12 @@ def story_processor(old_story):
219218
"""
220219
sql.execute(self.working_open_doors, query)
221220

222-
self.logger.debug(f" tags...")
221+
self.logger.debug(" tags...")
223222
tags = self._convert_story_tags(old_story)
224223
# pass the new sql to be used instead of the main one
225224
self._convert_tags_join(new_story, tags, sql)
226225

227-
self.logger.debug(f" authors...")
226+
self.logger.debug(" authors...")
228227
self._convert_author_join(new_story, old_story['uid'], sql)
229228
# Find if there are any coauthors for the work
230229
coauthors = self.fetch_coauthors(new_story, sql)

efiction/original.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Step 01
33
"""
4-
import os
54
from configparser import ConfigParser
65
from logging import Logger
76

efiction/simplified.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import re
32
from configparser import ConfigParser
43
from logging import Logger

efiction/tag_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def check_for_nonstandard_tag_tables(self) -> bool:
2929
if tag_table_name == 'rating':
3030
# Only one rating per story, so story rating should be single number
3131
# that exactly matches rating id
32-
query = f"SELECT count(*) as cnt FROM stories WHERE rid NOT IN (SELECT rid FROM ratings);"
32+
query = "SELECT count(*) as cnt FROM stories WHERE rid NOT IN (SELECT rid FROM ratings);"
3333
count: List[Dict[str, int]] = self.sql.execute_and_fetchall(self.working_original, query)
3434
tag_tables['rating'] = bool(count and count[0]['cnt'] > 0)
3535
else:
@@ -53,7 +53,7 @@ def check_for_nonstandard_tag_tables(self) -> bool:
5353
tags = list(map(lambda story_tags: story_tags[id_name].replace(',', ''), tags))
5454
int(''.join(tags))
5555
tag_tables[tag_table_name] = False
56-
except Exception as e:
56+
except Exception:
5757
# Non-integer in identifier
5858
tag_tables[tag_table_name] = True
5959
except Exception as e:

efiction/tests/test_chapters.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66

77
from efiction.chapters import EFictionChapters
8-
from opendoors.big_insert import BigInsert
98
from opendoors.config import ArchiveConfig
10-
from opendoors.mysql import SqlDb
11-
from opendoors.utils import get_full_path, normalize, remove_output_files
9+
from opendoors.utils import get_full_path, normalize
1210

1311

1412
def get_data():

efiction/tests/test_metadata.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import datetime
22
from unittest import TestCase
3-
from unittest.mock import MagicMock
43

5-
from efiction.metadata import EFictionMetadata
64
from efiction.tests.test_utils import load_fixtures, create_efiction_converter
7-
from opendoors.config import ArchiveConfig
8-
from opendoors.mysql import SqlDb
9-
from opendoors.utils import get_full_path, remove_output_files
5+
from opendoors.utils import remove_output_files
106

117

128
class TestEFictionConverter(TestCase):

efiction/tests/test_original.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import glob
2-
import os
3-
import re
41
from unittest import TestCase
52
from unittest.mock import MagicMock, patch
63

opendoors/mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def read_table_to_dict(self, database: str, tablename: str):
7373
try:
7474
cursor.execute(f"SELECT * FROM {database}.{tablename};")
7575
return cursor.fetchall()
76-
except Exception as e:
76+
except Exception:
7777
self.logger.info(f"No table {tablename} in {database}...")
7878
return []
7979

opendoors/progress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def continue_from_last(config: ConfigParser, logger: Logger, sql: SqlDb, steps:
2929
next_step = config['Processing']['next_step'] = step.next_step
3030
update_done_steps(config, done_steps, step_to_run)
3131
else:
32-
restart_yn = input(f"All steps have been completed for this archive. Do you want to\n"
32+
restart_yn = input("All steps have been completed for this archive. Do you want to\n"
3333
"1. Restart from step 1\n"
3434
"2. Exit (default - press Enter)\n>> ")
3535
if restart_yn == "1":
3636
next_step = "01"
3737
else:
3838
run_next = False
39-
except Exception as e:
39+
except Exception:
4040
logger.error(traceback.format_exc())
4141

4242

0 commit comments

Comments
 (0)