import time


def _ConvertTimes(dictionary):
  """Replaces all keys that end in '_ts' with human readable times.

  It seems from sample results that *_ts in the response are specified in
  microseconds since the UNIX epoch.

  Args:
    dictionary: A dictionary with the original data.

  Returns:
    A copy of the original dictionary with appropriate replacements.
  """
  result = dictionary.copy()

  for key in result:
    if key.endswith('_ts'):
      # We cast as float because the data comes as a string containing the
      # number of microseconds since the unix epoch.
      time_seconds = float(result[key]) / 1000000
      time_string = time.ctime(time_seconds)
      result[key.replace('_ts', '_utc')] = time_string
      result.pop(key)
  return result