<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_event(self, service_name, event_type, values_to_sub):
 """ opens the event json, substitutes the values in, and returns the customized event json Parameters service_name: string name of the top level service (S3, apigateway, etc) event_type: string name of the event underneath the service values_to_sub: dict key/value pairs to substitute into the json Returns ------- renderer.render():
 string string version of the custom event json """


        # set variables for easy calling
        tags = self.event_mapping[service_name][event_type]['tags']
        values_to_sub = self.encode(tags, 'encoding', values_to_sub)

        # construct the path to the Events json file
        this_folder = os.path.dirname(os.path.abspath(__file__))
        file_name = self.event_mapping[service_name][event_type]['filename'] + ".json"
        file_path = os.path.join(this_folder, "events", service_name, file_name)

        # open the file
        with open(file_path) as f:
            data = json.load(f)

        data = json.dumps(data, indent=2)

        # return the substituted file
        return renderer.render(data, values_to_sub)