stats: Fix config stuff on the CLI and in function args
Various errors fixed. whoopsie Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import asyncio
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from . import config
|
||||||
from .pull import pull
|
from .pull import pull
|
||||||
from .http import run_app
|
from .http import run_app
|
||||||
from .hist import generate_histogram_svg
|
from .hist import generate_histogram_svg
|
||||||
@@ -33,7 +34,7 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
pull_parser.add_argument(
|
pull_parser.add_argument(
|
||||||
"--generate-histogram",
|
"--generate-histogram",
|
||||||
action="store_true",
|
type=lambda x: x.lower() in ['true', '1', 'yes', 'y'],
|
||||||
help="Generate a histogram SVG if any new posts are pulled",
|
help="Generate a histogram SVG if any new posts are pulled",
|
||||||
default=config.PULL_GENERATE_HISTOGRAM,
|
default=config.PULL_GENERATE_HISTOGRAM,
|
||||||
)
|
)
|
||||||
@@ -75,7 +76,7 @@ def main():
|
|||||||
case "serve":
|
case "serve":
|
||||||
run_app()
|
run_app()
|
||||||
case "hist":
|
case "hist":
|
||||||
generate_histogram_svg()
|
generate_histogram_svg(config.HISTOGRAM_PATH)
|
||||||
case command:
|
case command:
|
||||||
assert (
|
assert (
|
||||||
False
|
False
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ HTTP_RESULTS_PER_PAGE = default("HTTP_RESULTS_PER_PAGE", 100)
|
|||||||
|
|
||||||
STATIC_HANDLER = one_of_default("STATIC_HANDLER", ("remote", "local"), "local")
|
STATIC_HANDLER = one_of_default("STATIC_HANDLER", ("remote", "local"), "local")
|
||||||
STATIC_LOCAL_PATH = Path(default("STATIC_LOCAL_PATH", "static"))
|
STATIC_LOCAL_PATH = Path(default("STATIC_LOCAL_PATH", "static"))
|
||||||
STATIC_LOCAL_FOLLOW_SYMLINKS = default_bool("STATIC_LOCAL_FOLLOW_SYMLINKS")
|
STATIC_LOCAL_FOLLOW_SYMLINKS = default_bool("STATIC_LOCAL_FOLLOW_SYMLINKS", default_value=True)
|
||||||
STATIC_ROOT = default("STATIC_ROOT", "/static")
|
STATIC_ROOT = default("STATIC_ROOT", "/static")
|
||||||
|
|
||||||
HISTOGRAM_PATH = Path(default("HISTOGRAM_PATH", "static/histogram.svg"))
|
HISTOGRAM_PATH = Path(default("HISTOGRAM_PATH", "static/histogram.svg"))
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def histogram_svg():
|
|||||||
return svg
|
return svg
|
||||||
|
|
||||||
|
|
||||||
def generate_histogram_svg(path: Path = HISTOGRAM_PATH):
|
def generate_histogram_svg(path: Path):
|
||||||
log.info("Generating and writing histogram SVG to %s", path)
|
log.info("Generating and writing histogram SVG to %s", path)
|
||||||
svg = histogram_svg()
|
svg = histogram_svg()
|
||||||
path = path.write_text(svg)
|
path = path.write_text(svg)
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ async def get_thumb(thumb_path: Union[str, Path], post: dict) -> Optional[bytes]
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
async def pull(generate_histogram: bool = config.GENERATE_HISTOGRAM):
|
async def pull(
|
||||||
|
generate_histogram: bool = config.PULL_GENERATE_HISTOGRAM,
|
||||||
|
histogram_path: Path = config.HISTOGRAM_PATH,
|
||||||
|
):
|
||||||
# TODO(args) --db-path arg
|
# TODO(args) --db-path arg
|
||||||
db = get_db()
|
db = get_db()
|
||||||
|
|
||||||
@@ -209,7 +212,7 @@ async def pull(generate_histogram: bool = config.GENERATE_HISTOGRAM):
|
|||||||
log.exception("error inserting data")
|
log.exception("error inserting data")
|
||||||
log.info("Continuing")
|
log.info("Continuing")
|
||||||
if updated and generate_histogram:
|
if updated and generate_histogram:
|
||||||
generate_histogram_svg()
|
generate_histogram_svg(histogram_path)
|
||||||
|
|
||||||
# Finish off thumbnail jobs
|
# Finish off thumbnail jobs
|
||||||
await asyncio.gather(*download_jobs)
|
await asyncio.gather(*download_jobs)
|
||||||
|
|||||||
Reference in New Issue
Block a user