How to use the yfpy.utils.complex_json_handler function in yfpy

To help you get started, we’ve selected a few yfpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uberfastman / yfpy / yfpy / data.py View on Github external
# change data save directory
        if new_data_dir:
            logger.debug("Data directory changed from {} to {}.".format(self.data_dir, new_data_dir))
            self.update_data_dir(new_data_dir)

        # create full directory path if any directories in it do not already exist
        if not os.path.exists(self.data_dir):
            os.makedirs(self.data_dir)

        # run the actual yfpy query and retrieve the query results
        data = self.get(yf_query, params)

        # save the retrieved data locally
        saved_data_file_path = os.path.join(self.data_dir, file_name + ".json")
        with open(saved_data_file_path, "w", encoding="utf-8") as data_file:
            json.dump(data, data_file, ensure_ascii=False, indent=2, default=complex_json_handler)
        logger.debug("Data saved locally to: {}".format(saved_data_file_path))
        return data
github uberfastman / yfpy / yfpy / models.py View on Github external
def to_json(self):
        """Serialize the class object to json.

        :return: json string derived from the serializable version of the class object
        """
        return json.dumps(self.serialized(), indent=2, default=complex_json_handler, ensure_ascii=False)
github uberfastman / yfpy / yfpy / query.py View on Github external
# unpack, parse, and assign data types to all retrieved data content
            unpacked = unpack_data(raw_response_data, YahooFantasyObject)
            logger.debug(
                "Unpacked and parsed JSON (Yahoo fantasy data wth parent type: {}):\n{}".format(
                    data_type_class, unpacked))

            self.executed_queries.append({
                "url": response.url,
                "response_status_code": response.status_code,
                "response": response
            })

            # cast highest level of data to type corresponding to query (if type exists)
            query_data = data_type_class(unpacked) if data_type_class else unpacked
            if self.all_output_as_json:
                return json.dumps(query_data, indent=2, default=complex_json_handler, ensure_ascii=False)
            else:
                return query_data

        else:
            logger.error("CANNOT RUN YAHOO QUERY WHILE USING OFFLINE MODE!")