Skip to content

Commit

Permalink
style: fix tools
Browse files Browse the repository at this point in the history
  • Loading branch information
y-young committed Apr 6, 2024
1 parent 40f8d08 commit 78ee02f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Empty file added tools/__init__.py
Empty file.
Empty file added tools/database/__init__.py
Empty file.
17 changes: 8 additions & 9 deletions tools/database/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=import-error, wrong-import-position, global-statement
"""
Helper script to scan artworks from local directory and write metadata to database.
Run this script in the root directory of the project.
Expand All @@ -18,7 +17,8 @@
from nazurin.sites.moebooru.config import COLLECTIONS as MOEBOORU_COLLECTIONS

logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
)
logger = logging.getLogger("helper")
sites = SiteManager()
Expand Down Expand Up @@ -51,15 +51,15 @@ def scan():
"danbooru_new": r"^danbooru (\d+)",
"zerochan": r"^Zerochan (\d+)",
}
global file_cnt
global file_cnt # noqa: PLW0603
files = glob.glob(directory + "*")
for path in files:
file_cnt = file_cnt + 1
filename = path[len(directory) :]
flag = False
source = None

for source, pattern in patterns.items():
for _, pattern in patterns.items():
match = re.search(pattern, filename, re.IGNORECASE)
if match:
flag = True
Expand Down Expand Up @@ -130,20 +130,20 @@ def print_result():


def main():
global artworks, success, directory
global artworks, success, directory # noqa: PLW0603
for source in SITES:
processed[source] = []
directory = input("Directory path (ends with slash): ")
print("Skip sites(enter site name in SITES, separated with comma):")
print("SITES=" + str(SITES))
logger.info("Skip sites(enter site name in SITES, separated with comma):")
logger.info("SITES=%s", SITES)
skipped = input()
skipped = skipped.split(",")
db = Database().driver()

for filename, source, match in scan():
origin_id, site = parse_source(source, match)
if source == "danbooru_new":
source = site = "danbooru"
source = site = "danbooru" # noqa: PLW2901
if site in skipped:
continue

Expand All @@ -157,7 +157,6 @@ def main():

try:
data = process(filename, source, match, origin_id)
# pylint: disable=broad-except
except Exception as err:
logger.error("❌ %s: (id: %s) %s", filename, origin_id, err)
error.append((filename, origin_id, err))
Expand Down
2 changes: 1 addition & 1 deletion tools/set_fly_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
config = dotenv_values(".env")
secrets = " ".join([f'{k}="{v}"' for k, v in config.items()])
command = f"fly secrets set {secrets}"
print(command)
print(command) # noqa: T201
subprocess.run(command, shell=True, check=True)

0 comments on commit 78ee02f

Please sign in to comment.