import json, os
from app import arg_parser

args = arg_parser.ArgParser().parse()


class ConfigParser:
    config = None

    def __init__(self):
        self.loadConfig()

    def loadConfig(self):
        ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(ROOT_DIR, '../config.json')

        if args.config:
            path = args.config

        with open(path, 'r') as f:
            self.config = json.load(f)

            if args.geoLatitude:
                self.config['geo']['latitude'] = args.geoLatitude
            if args.geoLongitude:
                self.config['geo']['longitude'] = args.geoLongitude
            if args.user:
                self.config['user'] = args.user
            if args.geoAccuracy:
                self.config['geo']['accuracy'] = args.geoAccuracy

        return self.config