-
Notifications
You must be signed in to change notification settings - Fork 2
/
makedb.py
38 lines (31 loc) · 1.32 KB
/
makedb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from lib.prepare_db import MakeDb
from lib.db_functions import DbFunctions
import logging
import os
import sys
import configparser
# Create a ConfigParser object
config = configparser.ConfigParser()
# Read the configuration from the file
config.read('company_dns.conf')
# Set up the logging
logging.basicConfig(format='%(levelname)s:\t%(asctime)s [module: %(name)s] %(message)s', level=logging.INFO)
logger = logging.getLogger(__file__)
# Check to see if the database cache file exists and if so log the event and exit
if os.path.exists(config['db_control']['DB_NAME']):
logger.info('The database cache file %s already exists, exiting.', config['db_control']['DB_NAME'])
sys.exit(0)
# Check to see if the directory ./edgar_data exists if not create it
logger.info('Checking for the existence of the directory %s.', config['edgar_data']['EDGAR_DATA_DIR'])
try:
os.mkdir(config['edgar_data']['EDGAR_DATA_DIR'])
logger.info('%s does not exist creating it.', config['edgar_data']['EDGAR_DATA_DIR'])
except FileExistsError:
logger.info('%s exists skipping creation.', config['edgar_data']['EDGAR_DATA_DIR'])
pass
# Remove the existing database cache file
db_functions = DbFunctions(config=config)
db_functions.clean_db()
# Construct the database object and build the database
new_db = MakeDb(config=config)
new_db.build_db()