-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Have multiple record types for the comments section.
- Loading branch information
Showing
12 changed files
with
248 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
|
||
from .api import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
from dataclasses import dataclass | ||
from loguru import logger as log | ||
|
||
|
||
from acd.dbextract import DbExtract | ||
from acd.unzip import Unzip | ||
|
||
|
||
@dataclass | ||
class AcdDatabase: | ||
input_filename: os.PathLike | ||
output_filename: str | ||
_temp_dir: str = "build" # tempfile.mkdtemp() | ||
|
||
def __post_init__(self): | ||
if not os.path.exists(os.path.join(self._temp_dir)): | ||
os.makedirs(self._temp_dir) | ||
|
||
log.info("Extracting ACD database file") | ||
unzip = Unzip(self.input_filename) | ||
unzip.write_files(self._temp_dir) | ||
|
||
log.info("Getting records from ACD Comps file and storing in sqllite database") | ||
self.comps_db = DbExtract(os.path.join(self._temp_dir, "Comps.Dat")).read() | ||
|
||
log.info("Getting records from ACD SbRegion file and storing in sqllite database") | ||
self.sb_region_db = DbExtract(os.path.join(self._temp_dir, "SbRegion.Dat")).read() | ||
|
||
log.info("Getting records from ACD Comments file and storing in sqllite database") | ||
self.comments_db = DbExtract(os.path.join(self._temp_dir, "Comments.Dat")).read() | ||
|
||
log.info("Getting records from ACD Nameless file and storing in sqllite database") | ||
self.nameless_db = DbExtract(os.path.join(self._temp_dir, "Nameless.Dat")).read() | ||
|
||
def extract_to_file(self): | ||
directory = os.path.join(self._temp_dir, "comps_db") | ||
if not os.path.exists(os.path.join(directory)): | ||
os.makedirs(directory) | ||
for count, record in enumerate(self.comps_db.records.record): | ||
with open(os.path.join(directory, str(count)), "wb") as out_file: | ||
out_file.write(record.record.record_buffer) | ||
|
||
directory = os.path.join(self._temp_dir, "sb_region_db") | ||
if not os.path.exists(os.path.join(directory)): | ||
os.makedirs(directory) | ||
for count, record in enumerate(self.sb_region_db.records.record): | ||
with open(os.path.join(directory, str(count)), "wb") as out_file: | ||
out_file.write(record.record.record_buffer) | ||
|
||
directory = os.path.join(self._temp_dir, "comments_db") | ||
if not os.path.exists(os.path.join(directory)): | ||
os.makedirs(directory) | ||
for count, record in enumerate(self.comments_db.records.record): | ||
with open(os.path.join(directory, str(count)), "wb") as out_file: | ||
out_file.write(record.record.record_buffer) | ||
|
||
directory = os.path.join(self._temp_dir, "nameless_db") | ||
if not os.path.exists(os.path.join(directory)): | ||
os.makedirs(directory) | ||
for count, record in enumerate(self.nameless_db.records.record): | ||
with open(os.path.join(directory, str(count)), "wb") as out_file: | ||
out_file.write(record.record.record_buffer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.