1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00
gallery-dl/scripts/build_testresult_db.py
Mike Fährmann abbd45d0f4
update handling of extractor URL patterns
When loading extractor classes during 'extractor.find(…)', their
'pattern' attribute will be replaced with a compiled version of itself.
2019-02-08 20:08:16 +01:00

56 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
import sys
import os.path
import datetime
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.realpath(ROOTDIR))
from gallery_dl import extractor, job, config
from test.test_results import setup_test_config
# filter test cases
tests = [
(idx, extr, url, result)
for extr in extractor.extractors()
if hasattr(extr, "test") and extr.test
if len(sys.argv) <= 1 or extr.category in sys.argv
for idx, (url, result) in enumerate(extr._get_tests())
if result
]
# setup target directory
path = os.path.join(ROOTDIR, "archive/testdb", str(datetime.date.today()))
os.makedirs(path, exist_ok=True)
for idx, extr, url, result in tests:
# filename
name = "{}-{}-{}.json".format(extr.category, extr.subcategory, idx)
print(name)
# config values
setup_test_config()
if "options" in result:
for key, value in result["options"]:
config.set(key.split("."), value)
if "range" in result:
config.set(("image-range",), result["range"])
config.set(("chapter-range",), result["range"])
# write test data
try:
with open(os.path.join(path, name), "w") as outfile:
job.DataJob(url, file=outfile, ensure_ascii=False).run()
except KeyboardInterrupt:
sys.exit()