def get_sites()

in jobs/eam-integrations/scripts/api/Workday/Workday.py [0:0]


def get_sites():
    """Gets all sites from workday

  Parameters:
    None

  Returns:
    dict: a dict with location names as keys and the values are a dict like:
        {
          'name':        'Location Name',
          'timezone':    'Timezone converted to xMatters style',
          'address':     'Location Address',
          'country':     'Location Country',
          'city':        'Location City',
          'state':       'Location State',
          'postal_code': 'Location Postal Code',
        }

    One could successfully argue that the timezone format conversion
    should not happen here.


  """

    logger.info("Gathering all Workday sites")
    try:
        r = requests.get(
            _config.xmatters_integration["sites_url"],
            auth=(
                _config.xmatters_integration["username"],
                _config.xmatters_integration["password"],
            ),
            proxies=_config.proxies,
        )
        results = json.loads(r.text)
        # return results['Report_Entry']
        wd_locations = {}
        for site in results["Report_Entry"]:
            name = site["Work_Location_Name"]
            if name in wd_locations:
                continue
            else:
                if re.search(
                    "^GMT-03:30 Newfoundland Time",
                    site.get("Work_Location_Timezone", ""),
                ):
                    # fixup a stupid non-ascii character
                    site[
                        "Work_Location_Timezone"
                    ] = "GMT-03:30 Newfoundland Time (St. John's)"

                wd_locations[name] = {
                    "name": name,
                    "timezone": _config.workday_to_xmatters_tz[
                        site.get("Work_Location_Timezone", "")
                    ],
                    "address": site.get("Work_Location_Address", ""),
                    "country": site.get("Work_Location_Country", ""),
                    "city": site.get("Work_Location_City", ""),
                    "state": site.get("Work_Location_State", ""),
                    "postal_code": site.get("Work_Location_Postal_Code", ""),
                }
        return wd_locations

    except Exception:
        logger.critical(sys.exc_info()[0])
        raise