import logging
from web3 import Web3
import sys
import time
import meditation.meditation as meditation


if __name__ == "__main__":
    log_format = '%(asctime)s|%(name)s|%(levelname)s: %(message)s'

    logger = logging.getLogger("DFK-meditation")
    logger.setLevel(logging.DEBUG)
    logging.basicConfig(level=logging.INFO, format=log_format, stream=sys.stdout)

    rpc_server = 'https://api.harmony.one'
    logger.info("Using RPC server " + rpc_server)

    private_key = None  # set private key
    account_address = '0x2E7669F61eA77F02445A015FBdcFe2DE47083E02'
    gas_price_gwei = 10
    tx_timeout_seconds = 30
    w3 = Web3(Web3.HTTPProvider(rpc_server))

    active_meditations = meditation.get_active_meditations(account_address, rpc_server)
    logger.info("Pending meditation on address " + str(account_address) + ": "+str(active_meditations))

    level = 1
    hero_id = 1
    required_runes = meditation.get_required_runes(level, rpc_server)
    meditation.start_meditation(1, meditation.stat2id('strength'), meditation.stat2id('endurance'), meditation.stat2id('luck'),
                               meditation.ZERO_ADDRESS, private_key, w3.eth.getTransactionCount(account_address),
                               gas_price_gwei, tx_timeout_seconds, rpc_server, logger)
    hero_meditation = meditation.get_hero_meditation(hero_id, rpc_server)
    logger.info("Pending meditation "+str(hero_meditation))
    time.sleep(5)
    meditation.complete_meditation(hero_id, private_key, w3.eth.getTransactionCount(account_address),
                                  gas_price_gwei, tx_timeout_seconds, rpc_server, logger)


[((11, 13, 11, 48), 'logging.getLogger', 'logging.getLogger', ({(11, 31, 11, 47): '"""DFK-meditation"""'}, {}), "('DFK-meditation')", False, 'import logging\n'), ((13, 4, 13, 81), 'logging.basicConfig', 'logging.basicConfig', (), '', False, 'import logging\n'), ((24, 25, 24, 87), 'meditation.meditation.get_active_meditations', 'meditation.get_active_meditations', ({(24, 59, 24, 74): 'account_address', (24, 76, 24, 86): 'rpc_server'}, {}), '(account_address, rpc_server)', True, 'import meditation.meditation as meditation\n'), ((29, 21, 29, 69), 'meditation.meditation.get_required_runes', 'meditation.get_required_runes', ({(29, 51, 29, 56): 'level', (29, 58, 29, 68): 'rpc_server'}, {}), '(level, rpc_server)', True, 'import meditation.meditation as meditation\n'), ((33, 22, 33, 73), 'meditation.meditation.get_hero_meditation', 'meditation.get_hero_meditation', ({(33, 53, 33, 60): 'hero_id', (33, 62, 33, 72): 'rpc_server'}, {}), '(hero_id, rpc_server)', True, 'import meditation.meditation as meditation\n'), ((35, 4, 35, 17), 'time.sleep', 'time.sleep', ({(35, 15, 35, 16): '(5)'}, {}), '(5)', False, 'import time\n'), ((22, 14, 22, 43), 'web3.Web3.HTTPProvider', 'Web3.HTTPProvider', ({(22, 32, 22, 42): 'rpc_server'}, {}), '(rpc_server)', False, 'from web3 import Web3\n'), ((30, 35, 30, 65), 'meditation.meditation.stat2id', 'meditation.stat2id', ({(30, 54, 30, 64): '"""strength"""'}, {}), "('strength')", True, 'import meditation.meditation as meditation\n'), ((30, 67, 30, 98), 'meditation.meditation.stat2id', 'meditation.stat2id', ({(30, 86, 30, 97): '"""endurance"""'}, {}), "('endurance')", True, 'import meditation.meditation as meditation\n'), ((30, 100, 30, 126), 'meditation.meditation.stat2id', 'meditation.stat2id', ({(30, 119, 30, 125): '"""luck"""'}, {}), "('luck')", True, 'import meditation.meditation as meditation\n')]