示例#1
0
def run_discovery(mint, user):
    num_drones = mint.get_user_exploration_drones(user)
    cur_discoveries = mint.get_discoveries(user)
    cur_names = [disc['name'] for disc in cur_discoveries]

    disc = possibly_make_discovery(GLOBAL_DISCOVERY_CHANCE,
                                   num_drones,
                                   len(cur_discoveries),
                                   cur_names)
    if disc:
        cur_discoveries.append(disc)
        mint.set_discoveries(user, cur_discoveries)
        log_event(mint, user, "You have discovered a new %s named %s!" % (disc['type'], disc['name']))
def main():
    logging.info('Started main function')
    t0 = time.time()
    while True:
        t1 = time.time()
        logging.info('Loading positions')

        positions_ids = get_positions_ids()

        logging.info('Getting {} positions'.format(len(positions_ids)))
        if len(positions_ids) > 0:
            logging.info('Loading positions')

            positions = load_positions(positions_ids)

            logging.info('Process positions')

            process_positions(positions)

            logging.info('Positions parsing is finished')
            logging.info('Upgrade table')

            upgrade_table(positions)

            t2 = time.time()
            log_event("Finished preprocessing %d items in \"%s\" MODE" %
                      (len(positions_ids), MODE),
                      EVENT_TEXT_CONFIG,
                      time_delta=t2 - t1)
            logging.info("Finished preprocessing %d items in %s" %
                         (len(positions_ids), t2 - t1))
        else:
            if MODE == "daily":
                logging.info('Sleep')
                time.sleep(120 * 1000)
            elif MODE == "once":
                t3 = time.time()
                log_event(
                    "Finished preprocessing of all items in \"%s\" MODE" %
                    MODE,
                    EVENT_TEXT_CONFIG,
                    time_delta=t3 - t0)
                logging.info(
                    "Script in once mode. All item was processed. Exiting")
                sys.exit(0)
示例#3
0
def gen_resources(mint, user):
    discoveries = mint.get_discoveries(user)
    
    new_resources = defaultdict(lambda: 0)
    for disc in discoveries:
        update_resources(disc['resources'], new_resources)
        
    resources = mint.get_resources(user)
    new = {}
    types = ['light ores', 'heavy ores', 'rare ores', 'unique ores',
             'light gases', 'heavy gases', 'rare gases', 'unique gases',
             'consumables']
    for typ in types:
        new[typ] = resources.get(typ, 0) + int(new_resources[typ])

        if new_resources[typ] != 0:
            log_event(mint, user, "Your drones have extracted %d %s." % (new_resources[typ], typ))

    mint.set_resources(user, new)
    return new
def start_script():

    if namespace.daemon:
        logging.basicConfig(format=LOGGING_FORMAT,
                            datefmt='%Y.%m.%d %H:%M:%S',
                            level=LOGGING_LEVEL,
                            filename='/tmp/{}.log'.format(FILE_NAME))
    else:
        logging.basicConfig(format=LOGGING_FORMAT,
                            datefmt='%Y.%m.%d %H:%M:%S',
                            level=LOGGING_LEVEL)

    log_event("STARTED {}".format(SCRIPT_NAME), EVENT_TEXT_CONFIG)
    logging.info("STARTED {} ON MODE: {}".format(SCRIPT_NAME, MODE))

    try:
        main()
        log_event("FINISHED {}".format(SCRIPT_NAME), EVENT_TEXT_CONFIG)

    except BaseException as e:
        traceback.print_exc()
        log_event("ERROR IN {}: {}".format(SCRIPT_NAME, repr(e)),
                  EVENT_TEXT_CONFIG)