diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-06-01 17:01:20 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-06-01 17:01:20 -0700 |
commit | 57db2db336c08031324e44b2d2880fbd4b6893c9 (patch) | |
tree | f5ad462ab6b3e7d3ac7987049e8c604bd5ee9fbe /chocula/common.py | |
parent | 08867f9b8de576f0831e6bb9f7b88acddcc31dee (diff) | |
download | chocula-57db2db336c08031324e44b2d2880fbd4b6893c9.tar.gz chocula-57db2db336c08031324e44b2d2880fbd4b6893c9.zip |
'everything' at least partially working
Diffstat (limited to 'chocula/common.py')
-rw-r--r-- | chocula/common.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/chocula/common.py b/chocula/common.py index 54856c9..f515e6f 100644 --- a/chocula/common.py +++ b/chocula/common.py @@ -33,3 +33,30 @@ class DirectoryLoader(): cur.close() db.db.commit() return counts + +class KbartLoader(): + + source_slug: str = "GENERIC" + + def __init__(self, config: ChoculaConfig): + self.config = config + + def open_file(self) -> Iterable: + raise NotImplementedError() + + def parse_record(self, record) -> Optional[DirectoryInfo]: + raise NotImplementedError() + + def index_file(self, db) -> Counter: + print(f"##### Loading {self.source_slug} KBART...", file=sys.stderr) + counts: Counter = Counter() + cur = db.db.cursor() + for record in self.open_file(): + counts['total'] += 1 + info = self.parse_record(record) + if info: + status = db.insert_directory(info, cur=cur) + counts[status] += 1 + cur.close() + db.db.commit() + return counts |