from colorsys import rgb_to_hsv


def from_rgb_to_paletton_hue(rgb, paletton):
    """
    >>> p = Paletton()
    >>> print(from_rgb_to_paletton_hue((120, 0, 106), p))
    318
    """
    rhs_hue = round(rgb_to_hsv(*rgb)[0]*360)
    if rhs_hue not in paletton.HUE_OFFSETS:
        keys = sorted(paletton.HUE_OFFSETS.keys())
        closest_offset_index = sorted(keys + [rhs_hue]).index(rhs_hue)
        rhs_hue = keys[closest_offset_index-1]

    return paletton.HUE_OFFSETS[rhs_hue]