def add_new_record(record, region):
    '''
    Make a dictionary of all the data for a record.
    '''
    finders = Finders()
    finders.sub_images_id = session.query(SubImages.id)\
                .filter(SubImages.master_images_id == record.MasterFinders.master_images_id)\
                .filter(SubImages.region == region)\
                .one().id
    finders.master_finders_id = record.MasterFinders.id
    finders.object_name = record.MasterFinders.object_name
    finders.x = record.MasterFinders.ephem_x - ((record.MasterFinders.ephem_x // 425) * 425)
    finders.y = record.MasterFinders.ephem_y - ((record.MasterFinders.ephem_y // 425) * 425)
    session.add(finders)
def insert_record(moon_dict,  master_images_id):
    '''
    Make a new record to be in the master_finders table.
    '''
    record = MasterFinders()
    record.object_name = moon_dict['object']
    record.jpl_ra = moon_dict['jpl_ra']
    record.jpl_dec = moon_dict['jpl_dec']
    try:
        record.diameter = float(moon_dict['jpl_ang_diam'])
    except Exception as err:
        logging.critical('{0} {1} {2}'.format(
            type(err), err.message, sys.exc_traceback.tb_lineno))
    try:
        record.magnitude = float(moon_dict['jpl_APmag'])
    except Exception as err:
        logging.critical('{0} {1} {2}'.format(
            type(err), err.message, sys.exc_traceback.tb_lineno))
    record.master_images_id = master_images_id
    record.version = __version__
    session.add(record)
    session.commit()