def get_trigger_config(trigger_id): """ Get the configuration of a trigger :param trigger_id: id of the trigger :return: a dict containing the configuration of the trigger """ try: trigger_config = load_from_json_file( os.path.join(TRIGGERS_DIR, '%s.json' % trigger_id)) except IOError: # Trigger does not exist yet, return empty dict trigger_config = {} return trigger_config
def get_action_config(action_id): """ Get the configuration of an action :param action_id: id of the action :return: a dict containing the configuration of the action """ try: action_config = load_from_json_file( os.path.join(ACTIONS_DIR, '%s.json' % action_id)) except IOError: # Action does not exist yet, return empty dict action_config = {} return action_config
def check_authentication(headers, data): """ Checks if the headers contain valid authentication information This must include the following headers: - API_Key: an identifier for the account - API_Sign: a signature - API_Nonce: an integer, each request must have a nonce that is higher than the nonce of the previous request :param headers: The headers of the http request :param data: The json data of the http request :return: An AuthenticationStatus """ global LAST_NONCES api_keys = load_from_json_file(API_KEYS_FILE) if api_keys is None: return AuthenticationStatus.INVALID_JSON_FILE if 'API_Key' not in headers: return AuthenticationStatus.NO_API_KEY if 'API_Sign' not in headers: return AuthenticationStatus.NO_SIGNATURE if 'API_Nonce' not in headers: return AuthenticationStatus.NO_NONCE api_key = headers['API_Key'] if api_key not in api_keys or 'secret' not in api_keys[api_key]: return AuthenticationStatus.INVALID_API_KEY try: nonce = int(headers['API_Nonce']) except Exception as ex: return AuthenticationStatus.INVALID_NONCE if api_key in LAST_NONCES and LAST_NONCES[api_key] >= nonce: return AuthenticationStatus.INVALID_NONCE LAST_NONCES[api_key] = nonce if headers['API_Sign'] == signature(data, nonce, api_keys[api_key]['secret']): return AuthenticationStatus.OK else: return AuthenticationStatus.INVALID_SIGNATURE
def load(self, payment_request_id): try: data = load_from_json_file(filename=os.path.join(PAYMENT_PROCESSOR_DIR, '%s.json' % payment_request_id)) except IOError as ex: LOG.error('Payment_request_id not found: %s' % ex) raise Exception('Unknown payment request id: %s' % payment_request_id) self.payment_request_id = payment_request_id self.seller_id = data['seller_id'] self.amount_fiat = data['amount_fiat'] self.currency = data['currency'] self.price_btc = data['price_btc'] self.price_timestamp = data['price_timestamp'] self.amount_btc = data['amount_btc'] self.note = data['note'] self.status = data['status'] self.address = data['address'] self.txid = data['txid'] self.confirmations = data['confirmations']
value=mail_on_exception) current_python_exe = config.get(section='RESTAPI', option='python_exe', fallback='python3.10') python_exe = input('Enter the python exe to use (%s) ' % current_python_exe) or current_python_exe config.set(section='RESTAPI', option='python_exe', value=python_exe) # Authentication settings api_keys_file = os.path.join(PROGRAM_DIR, 'json', 'private', 'api_keys.json') if not os.path.isfile(api_keys_file): print('Initializing api keys') initialize_api_keys_file() api_keys = load_from_json_file(filename=api_keys_file) current_key = list(api_keys.keys())[0] key = input( 'Enter the API key or press enter to keep the current value (%s) ' % current_key) or current_key config.set(section='Authentication', option='key', value=key) current_secret = api_keys[key]['secret'] secret = input( 'Enter the API secret or press enter to keep the current value (%s) ' % current_secret) or current_secret config.set(section='Authentication', option='secret', value=secret) # Wallet settings current_wallet_dir = config.get(section='Wallet', option='wallet_dir')
import argparse import os import sys PROGRAM_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, PROGRAM_DIR) from darwin.evolver import Evolver from helpers.jsonhelpers import load_from_json_file if __name__ == "__main__": # Create main parser parser = argparse.ArgumentParser( description='Evolver command line interface', formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('config', help='name of the configuration file to use') # Parse the command line arguments args = parser.parse_args() evolver = Evolver() # evolver.save_config(filename=args.config) # Read the configuration config = load_from_json_file(filename=args.config) evolver.load_config(config) evolver.print_settings() evolver.start()
def load_directory(self, directory): filenames = glob.glob(os.path.join(directory, '*.json')) for filename in filenames: genome_data = load_from_json_file(filename=filename) self.load_genome(genome_data=genome_data)