<commit_before>import os
from os.path import expanduser
import configparser

class FunbotsConfig :
    '''
    Retrieve configuration from configuration file.
    Configuration file is retrieved following this logic:
        look for system variable "FUNBOTS_CONFIGURATION_FILE",
            if existing, load the file using value specified by FUNBOTS_CONFIGURATION_FILE
            if not existing, use "~/funbots/funbots.init"
    '''

    class __OnlyOne:
        def __init__(self, arg):
            self.conf = arg
        def __str__(self):
            return repr(self) + self.conf

    ## static variable
    instance = None

    def __init__(self):
        if FunbotsConfig.instance is None:
            filePath=os.environ.get('FUNBOTS_CONFIGURATION_FILE')
            if filePath is None:
                home = expanduser("~")
                filePath = os.path.join(home, 'funbots/funbots.init')
            conf = configparser.ConfigParser()
            conf.read(filePath)
            ##print(conf.sections())
            FunbotsConfig.instance = FunbotsConfig.__OnlyOne(conf)

    def googleVisionKey(self) :
        return self.instance.conf['Google Vision']['gvkey']<commit_msg>make the google cloud service working for raspberry pi. In Mac a key is ok. but in raspberry pi, it seems service account json credential file is needed.<commit_after>import os
from os.path import expanduser
import configparser

class FunbotsConfig :
    '''
    Retrieve configuration from configuration file.
    Configuration file is retrieved following this logic:
        look for system variable "FUNBOTS_CONFIGURATION_FILE",
            if existing, load the file using value specified by FUNBOTS_CONFIGURATION_FILE
            if not existing, use "~/funbots/funbots.init"
    '''

    class __OnlyOne:
        def __init__(self, arg):
            self.conf = arg
        def __str__(self):
            return repr(self) + self.conf

    ## static variable
    instance = None

    def __init__(self):
        if FunbotsConfig.instance is None:
            filePath=os.environ.get('FUNBOTS_CONFIGURATION_FILE')
            if filePath is None:
                home = expanduser("~")
                filePath = os.path.join(home, 'funbots/funbots.init')
                credFile = os.path.join(home, 'funbots/baymax-googlekey.txt')
                print("filePath=" + filePath)
                os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credFile
            conf = configparser.ConfigParser()
            conf.read(filePath)
            print(conf.sections())
            FunbotsConfig.instance = FunbotsConfig.__OnlyOne(conf)

    def googleVisionKey(self) :
        ##print(self.instance.conf['Google Vision']['gvkey'])
        return self.instance.conf['Google Vision']['gvkey']
{'fraction_non_alphanumeric': 0.08715925394548063, 'fraction_numerical': 0.0, 'mean_word_length': 2.456009913258984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506746', 'n_tokens_mistral': 782, 'n_tokens_neox': 758, 'n_words': 205}