How to use the yfpy.utils.unpack_data 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 / query.py View on Github external
raw_response_data = [
                            {data_key_list[i][0]: raw_response_data[data_key_list[i][0]]},
                            {data_key_list[i][1]: raw_response_data[data_key_list[i][1]]}
                        ]
                    else:
                        raw_response_data = raw_response_data.get(data_key_list[i])

            if raw_response_data:
                logger.debug("Response (Yahoo fantasy data extracted from: {}): {}".format(data_key_list,
                                                                                           raw_response_data))
            else:
                logger.error("NO DATA FOUND WHEN ATTEMPTING EXTRACTION FROM FIELDS {}".format(data_key_list))
                sys.exit()

            # 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
github uberfastman / yfpy / yfpy / data.py View on Github external
"""Load Yahoo fantasy football data already stored locally (CANNOT BE RUN IF save METHOD HAS NEVER BEEN RUN).

        :param file_name: name of file from which data will be loaded
        :param data_type_class: (optional) yfpy models.py class for data casting
        :param new_data_dir: (optional) full path to new desired directory from which data will be loaded
        :return:
        """
        # change data load directory
        if new_data_dir:
            self.update_data_dir(new_data_dir)

        # load selected data file
        saved_data_file_path = os.path.join(self.data_dir, file_name + ".json")
        if os.path.exists(saved_data_file_path):
            with open(saved_data_file_path, "r", encoding="utf-8") as data_file:
                unpacked = unpack_data(json.load(data_file), YahooFantasyObject)
                data = data_type_class(unpacked) if data_type_class else unpacked
            logger.debug("Data loaded locally from: {}".format(saved_data_file_path))
        else:
            raise FileNotFoundError(
                "FILE {} DOES NOT EXIST. CANNOT LOAD DATA LOCALLY WITHOUT HAVING PREVIOUSLY SAVED DATA!".format(
                    saved_data_file_path))
        return data