diff --git a/gallery_dl/archive.py b/gallery_dl/archive.py index edecb103..3df50116 100644 --- a/gallery_dl/archive.py +++ b/gallery_dl/archive.py @@ -41,7 +41,7 @@ def connect(path, prefix, format, def sanitize(name): - return '"' + name.replace('"', "_") + '"' + return f'''"{name.replace('"', '_')}"''' class DownloadArchive(): @@ -68,25 +68,25 @@ class DownloadArchive(): table = "archive" if table is None else sanitize(table) self._stmt_select = ( - "SELECT 1 " - "FROM " + table + " " - "WHERE entry=? " - "LIMIT 1") + f"SELECT 1 " + f"FROM {table} " + f"WHERE entry=? " + f"LIMIT 1") self._stmt_insert = ( - "INSERT OR IGNORE INTO " + table + " " - "(entry) VALUES (?)") + f"INSERT OR IGNORE INTO {table} " + f"(entry) VALUES (?)") if pragma: for stmt in pragma: - cursor.execute("PRAGMA " + stmt) + cursor.execute(f"PRAGMA {stmt}") try: - cursor.execute("CREATE TABLE IF NOT EXISTS " + table + " " - "(entry TEXT PRIMARY KEY) WITHOUT ROWID") + cursor.execute(f"CREATE TABLE IF NOT EXISTS {table} " + f"(entry TEXT PRIMARY KEY) WITHOUT ROWID") except self._sqlite3.OperationalError: # fallback for missing WITHOUT ROWID support (#553) - cursor.execute("CREATE TABLE IF NOT EXISTS " + table + " " - "(entry TEXT PRIMARY KEY)") + cursor.execute(f"CREATE TABLE IF NOT EXISTS {table} " + f"(entry TEXT PRIMARY KEY)") def add(self, kwdict): """Add item described by 'kwdict' to archive""" @@ -156,18 +156,18 @@ class DownloadArchivePostgresql(): table = "archive" if table is None else sanitize(table) self._stmt_select = ( - "SELECT true " - "FROM " + table + " " - "WHERE entry=%s " - "LIMIT 1") + f"SELECT true " + f"FROM {table} " + f"WHERE entry=%s " + f"LIMIT 1") self._stmt_insert = ( - "INSERT INTO " + table + " (entry) " - "VALUES (%s) " - "ON CONFLICT DO NOTHING") + f"INSERT INTO {table} (entry) " + f"VALUES (%s) " + f"ON CONFLICT DO NOTHING") try: - cursor.execute("CREATE TABLE IF NOT EXISTS " + table + " " - "(entry TEXT PRIMARY KEY)") + cursor.execute(f"CREATE TABLE IF NOT EXISTS {table} " + f"(entry TEXT PRIMARY KEY)") con.commit() except Exception as exc: log.error("%s: %s when creating '%s' table: %s", diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 12eeb4c0..132c5acd 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -853,7 +853,7 @@ class UrlJob(Job): stdout_write(url + "\n") if "_fallback" in kwdict: for url in kwdict["_fallback"]: - stdout_write("| " + url + "\n") + stdout_write(f"| {url}\n") def handle_queue(self, url, kwdict): if cls := kwdict.get("_extractor"): diff --git a/gallery_dl/path.py b/gallery_dl/path.py index 795564d5..71cba60b 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -122,7 +122,7 @@ class PathFormat(): basedir = config("base-directory") sep = os.sep if basedir is None: - basedir = "." + sep + "gallery-dl" + sep + basedir = f".{sep}gallery-dl{sep}" elif basedir: basedir = util.expand_path(basedir) altsep = os.altsep diff --git a/gallery_dl/transaction_id.py b/gallery_dl/transaction_id.py index 915b7b3f..f8769d9a 100644 --- a/gallery_dl/transaction_id.py +++ b/gallery_dl/transaction_id.py @@ -65,8 +65,8 @@ class ClientTransaction(): @cache(maxage=36500*86400, keyarg=1) def _extract_indices(self, ondemand_s, extractor): - url = ("https://abs.twimg.com/responsive-web/client-web" - "/ondemand.s." + ondemand_s + "a.js") + url = (f"https://abs.twimg.com/responsive-web/client-web" + f"/ondemand.s.{ondemand_s}a.js") page = extractor.request(url).text pattern = util.re_compile(r"\(\w\[(\d\d?)\],\s*16\)") return [int(i) for i in pattern.findall(page)] diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 4027ac6f..45ffc9c3 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -512,15 +512,15 @@ def cookiestxt_store(fp, cookies): value = cookie.value domain = cookie.domain - fp.write("\t".join(( - domain, - "TRUE" if domain and domain[0] == "." else "FALSE", - cookie.path, - "TRUE" if cookie.secure else "FALSE", - "0" if cookie.expires is None else str(cookie.expires), - name, - value + "\n", - ))) + fp.write( + f"{domain}\t" + f"{'TRUE' if domain and domain[0] == '.' else 'FALSE'}\t" + f"{cookie.path}\t" + f"{'TRUE' if cookie.secure else 'FALSE'}\t" + f"{'0' if cookie.expires is None else str(cookie.expires)}\t" + f"{name}\t" + f"{value}\n" + ) def code_to_language(code, default=None):