def action(self, ctx, *args, **params):
        action = ctx.info_name
        params_tmp = self.srv_info[action][self.PARAMS]

        params = self._param_encode(params,  params_tmp)

        pwd = os.path.dirname(os.path.abspath(__file__))
        filename = self.srv_info[action]["filename"] + ".js"
        path = os.path.join(pwd, "events", self.service, filename)

        with open(path) as f:
            data = f.read().strip()

        data = renderer.render(data, params)
        click.secho(json.dumps(json.loads(data), indent=2))
Ejemplo n.º 2
0
 def updateFile(path_to_new_file: str = "README.md",
                path_to_template_file: str = "directory_file",
                open_weather_query: str = None,
                open_weather_key: str = None,
                waka_time_api_key: str = None,
                format: str = "string") -> bool:
     '''Updates a file with the information gathered using the rest of the functions'''
     try:
         dictionary = getAll(open_weather_query=open_weather_query,
                             open_weather_key=open_weather_key,
                             waka_time_api_key=waka_time_api_key,
                             format=format)
         print(dictionary)
         with (open(path_to_template_file, "r")) as template_file:
             with (open(path_to_new_file, "w")) as new_file:
                 new_file.write(render(template_file, dictionary))
         return True
     except:
         return False
Ejemplo n.º 3
0
    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)