Skip to content

Instantly share code, notes, and snippets.

@0x9900
Last active February 26, 2025 15:35
Show Gist options
  • Save 0x9900/363a90736b4256478e091642f16e94f5 to your computer and use it in GitHub Desktop.
Save 0x9900/363a90736b4256478e091642f16e94f5 to your computer and use it in GitHub Desktop.
Purge QSOs
#!/usr/bin/env python
#
# BSD 3-Clause License
#
# Copyright (c) 2023, Fred W6BSD
# All rights reserved.
#
import logging
import os
from argparse import ArgumentParser
from pathlib import Path
from config import Config
from dbutils import connect_db
DEFAULT_DAYS = 2
REQ_PURGE = """
DELETE FROM cqcalls
WHERE status=2 AND EXTRA = "{}" AND time < datetime('now', '{} day');
"""
def purge_records(dbname: Path, extra: str, purge_time: int) -> None:
purge_time = abs(purge_time) * -1 # make sure we have a negative number
request = REQ_PURGE.format(extra, purge_time)
logging.debug(' '.join(request.strip().splitlines()))
conn = connect_db(dbname)
with conn:
curs = conn.cursor()
curs.execute(request)
logging.info("%d records deleted", curs.rowcount)
def main() -> None:
logging.basicConfig(
format='%(asctime)s - %(levelname)-5s %(lineno)3d:%(module)-8s - %(message)s',
datefmt='%H:%M:%S', level=logging.getLevelName(os.getenv('LOG_LEVEL', 'INFO'))
)
parser = ArgumentParser(description="Purge VOTA and POTA entries from the ft8ctrl database.")
parser.add_argument("-c", "--config", help="Name of the configuration file")
parser.add_argument("-d", "--days", type=int, required=True,
help="Days after which to expire")
parser.add_argument("-e", "--extra", default="POTA",
help="What extra field to expire [default: %(default)s]")
opts = parser.parse_args()
opts.extra = opts.extra.upper()
config = Config(opts.config)
config = config['ft8ctrl']
db_name = Path(config.db_name).expanduser()
logging.info("Database: %s", db_name)
logging.info("Purging %s records older than %d days", opts.extra, opts.days)
purge_records(db_name, opts.extra, opts.days)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment