Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: automated archive crashes #83

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions automated_archive/aa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
import codecs
import re
import os
from pathlib import Path
from html.parser import HTMLParser

from pymysql import connect
Expand Down Expand Up @@ -123,7 +123,7 @@ def _extract_fandoms(args, record):


def _create_mysql(args, FILES, log):
db = connect(args.db_host, args.db_user, args.db_password, "")
db = connect(host=args.db_host, user=args.db_user, password=args.db_password, db="")
cursor = db.cursor()
DATABASE_NAME = args.temp_db_database

Expand All @@ -132,12 +132,12 @@ def _create_mysql(args, FILES, log):
cursor.execute("create database {0};".format(DATABASE_NAME))
cursor.execute("use {0}".format(DATABASE_NAME))

sql = Sql(args)
codepath = os.path.dirname(os.path.realpath(__file__))

sql.run_script_from_file(
codepath + "/shared_python/create-open-doors-tables.sql", database=DATABASE_NAME
sql = Sql(args, log)
script_path = (
Path(__file__).parent.parent / "shared_python" / "create-open-doors-tables.sql"
)

sql.run_script_from_file(script_path, database=DATABASE_NAME)
db.commit()

authors = [
Expand Down
3 changes: 2 additions & 1 deletion shared_python/Chapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def _gather_and_dedupe(self, chapters_path, extensions, has_ids=False):
for cid, duplicate in duplicate_chapters.items():
# look up the author id and add that one to the file_names list
sql_author_id = self.sql.execute_and_fetchall(
"SELECT author_id FROM chapters WHERE id = {0}".format(cid)
self.sql.database,
"SELECT author_id FROM chapters WHERE id = {0}".format(cid),
)
if len(sql_author_id) > 0:
author_id = sql_author_id[0][0]
Expand Down
6 changes: 5 additions & 1 deletion shared_python/Sql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
from pathlib import Path
from typing import Union
import warnings

# ignore unhelpful MySQL warnings
Expand Down Expand Up @@ -53,7 +55,9 @@ def execute_and_fetchall(self, database: str, statement: str):
self.conn.commit()
return cursor.fetchall()

def run_script_from_file(self, filename, database, initial_load=False):
def run_script_from_file(
self, filename: Union[str, Path], database, initial_load=False
):
# Open and read the file as a single buffer
fd = open(filename, "r")
sqlFile = fd.read()
Expand Down
4 changes: 1 addition & 3 deletions shared_python/Tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def populate_tag_table(
if isinstance(
tag_col_lookup[col], str
): # Probably AA or a custom archive
cleaned_tag = (
val.encode("utf-8").replace("'", "'").strip()
)
cleaned_tag = val.replace("'", "'").strip()

values.append(
'({0}, "{1}", "{2}", "{3}")'.format(
Expand Down
Loading