import sqlite3


def get_twinkles_visits(opsim_db_file, fieldID=1427):
    """
    Return a sorted list of visits for a given fieldID from an OpSim
    db file.

    Parameters
    ----------
    obsim_db_file : str
        Filename of the OpSim db sqlite file
    fieldID : int, optional
        ID number of the field for which to return the visit numbers.
        The default value is the Twinkles field.

    Returns
    -------
    list : A list of obsHistIDs (i.e., visit numbers).

    Since a given visit can belong to more than one proposal, there
    may be multiple rows in the Summary table with the corresponding
    obsHistID.  This function removes the duplicates.
    """
    connect = sqlite3.connect(opsim_db_file)
    query = """select distinct obsHistID from Summary where fieldID=%i
               order by obsHistID asc""" % fieldID
    obsHistIDs = [x[0] for x in connect.execute(query)]
    return obsHistIDs