Пример #1
0
    def _parse_module_index_trend_estimates(self, modules_dict, module_name):
        """
        Method to parse the indexTrend module returned from the Yahoo Finance API call. The indexTrend module is
        uniquely parsed because it contains two separate pieces of data: The index trend's information and the index
        trend's estimates. This method will parse the index trend's estimates portion of the indexTrend.
        :param modules_dict: A dictionary containing all the modules.
        :type modules_dict: dict
        :param module_name: The name of the module to be parsed.
        :type module_name: str
        :return: A tuple containing a dataframe containing the company profile and None, or None and an error.
        :rtype: tuple
        """

        # Attempt to find the indexTrend module and the estimates submodule. If the module is not found, then it will
        # return None and a YahooModuleNotFoundError.
        try:
            index_trend_info = modules_dict[module_name]
            index_trend_estimates = index_trend_info['estimates']

        except Exception as e:
            return None, YahooExceptions.YahooModuleNotFoundError(e)

        # Attempt to get a formatted dataframe from the module. If there was an error formatting the dataframe, then it
        # will return None and a YahooModuleFormatError.
        try:
            index_trend_estimates = self._format_dataframe(
                index_trend_estimates)

        except Exception as e:
            return None, YahooExceptions.YahooModuleFormatError(e)

        # If the module was found and formatted, then it will return a dataframe containing the company officers
        # information and None since there was no error.
        return index_trend_estimates, None
Пример #2
0
    def _parse_module_earnings_finance_quarterly(self, modules_dict,
                                                 module_name):
        """
        Method to parse the earnings module returned from the Yahoo Finance API call. The earnings module is uniquely
        parsed because it contains four separate pieces of data: The company earnings estimates, the company quarterly
        earnings estimates, the company's yearly financials, and the company's quarterly financials.
        This method will parse the company's quarterly financials.
        :param modules_dict: A dictionary containing all the modules.
        :type modules_dict: dict
        :param module_name: The name of the module to be parsed.
        :type module_name: str
        :return: A tuple containing a dataframe containing the company profile and None, or None and an error.
        :rtype: tuple
        """

        # Attempt to find the earnings, financialsChart, and quarterly submodule. If the module is not found, then it
        # will return None and a YahooModuleNotFoundError.
        try:
            module = modules_dict[module_name]
            financial_quarterly = module['financialsChart']['quarterly']

        except Exception as e:
            return None, YahooExceptions.YahooModuleNotFoundError(e)

        # Attempt to get a formatted dataframe from the module. If there was an error formatting the dataframe, then it
        # will return None and a YahooModuleFormatError.
        try:
            financial_quarterly = self._format_dataframe(financial_quarterly)

        except Exception as e:
            return None, YahooExceptions.YahooModuleFormatError(e)

        # If the module was found and formatted, then it will return a dataframe containing the company officers
        # information and None since there was no error.
        return financial_quarterly, None
Пример #3
0
    def _parse_module_asset_profile_profile(self, modules_dict, module_name):
        """
        Method to parse the assetProfile module returned from the Yahoo Finance API call. The assetProfile module is
        uniquely parsed because it contains two separate pieces of data: The company profile and the company officers.
        This method will parse the profile portion of the assetProfile.
        :param modules_dict: A dictionary containing all the modules.
        :type modules_dict: dict
        :param module_name: The name of the module to be parsed.
        :type module_name: str
        :return: A tuple containing a dataframe containing the company profile and None, or None and an error.
        :rtype: tuple
        """

        # Attempt to find the assetProfile module. If the module is not found, then it will return None and a
        # YahooModuleNotFoundError.
        try:
            profile_dict = modules_dict[module_name]

        except Exception as e:
            return None, YahooExceptions.YahooModuleNotFoundError(e)

        # Attempt to get a formatted dataframe from the module. If there was an error formatting the dataframe, then it
        # will return None and a YahooModuleFormatError.
        try:
            # We are going to remove the company officer's submodule to be parsed later.
            del profile_dict['companyOfficers']
            profile = self._format_dataframe(profile_dict)

        except Exception as e:
            return None, YahooExceptions.YahooModuleFormatError(e)

        # If the module was found and formatted, then it will return a dataframe containing the profile
        # information and None since there was no error.
        return profile, None
Пример #4
0
    def _parse_module_earnings_estimates(self, modules_dict, module_name):
        """
        Method to parse the earnings module returned from the Yahoo Finance API call. The earnings module is uniquely
        parsed because it contains four separate pieces of data: The company earnings estimates, the company quarterly
        earnings estimates, the company's yearly financials, and the company's quarterly financials.
        This method will parse the company's earnings estimates.
        :param modules_dict: A dictionary containing all the modules.
        :type modules_dict: dict
        :param module_name: The name of the module to be parsed.
        :type module_name: str
        :return: A tuple containing a dataframe containing the company profile and None, or None and an error.
        :rtype: tuple
        """

        # Attempt to find the earnings and the earningsChart submodule. If the module is not found, then it will
        # return None and a YahooModuleNotFoundError.
        try:
            earnings_estimates_dict = modules_dict[module_name][
                'earningsChart']
            del earnings_estimates_dict['quarterly']

        except Exception as e:
            return None, YahooExceptions.YahooModuleNotFoundError(e)

        # Attempt to get a formatted dataframe from the module. If there was an error formatting the dataframe, then it
        # will return None and a YahooModuleFormatError.
        try:
            # Sometimes the earnings data portion is returned as a list instead of a date.
            if isinstance(earnings_estimates_dict['earningsDate'], list):
                earnings_estimates_dict[
                    'earningsDate'] = earnings_estimates_dict['earningsDate'][
                        0]

            earnings_estimates = self._format_dataframe(
                earnings_estimates_dict)

        except Exception as e:
            return None, YahooExceptions.YahooModuleFormatError(e)

        # If the module was found and formatted, then it will return a dataframe containing the company officers
        # information and None since there was no error.
        return earnings_estimates, None
Пример #5
0
    def _parse_module_calendar_events_earnings(self, modules_dict,
                                               module_name):
        """
        Method to parse the calendarEvents module returned from the Yahoo Finance API call. The calendarEvents module is
        uniquely parsed because it contains two separate pieces of data: The company's earnings events and the company's
        dividends dates. This method will parse the company's earnings dates portion of the calendarEvents.
        :param modules_dict: A dictionary containing all the modules.
        :type modules_dict: dict
        :param module_name: The name of the module to be parsed.
        :type module_name: str
        :return: A tuple containing a dataframe containing the company profile and None, or None and an error.
        :rtype: tuple
        """

        # Attempt to find the calendarEvents module and the earnings submodule. If the module is not found, then it will
        # return None and a YahooModuleNotFoundError.
        try:
            calender_events_earnings = modules_dict[module_name]['earnings']

        except Exception as e:
            return None, YahooExceptions.YahooModuleNotFoundError(e)

        # Attempt to get a formatted dataframe from the module. If there was an error formatting the dataframe, then it
        # will return None and a YahooModuleFormatError.
        try:
            if isinstance(calender_events_earnings['earningsDate'], list):
                calender_events_earnings[
                    'earningsDate'] = calender_events_earnings['earningsDate'][
                        0]

            calender_events_earnings = self._format_dataframe(
                calender_events_earnings)
        except Exception as e:
            return None, YahooExceptions.YahooModuleFormatError(e)

        # If the module was found and formatted, then it will return a dataframe containing the company officers
        # information and None since there was no error.
        return calender_events_earnings, None
Пример #6
0
    def _parse_module(self, modules_dict, module_name, submodule_name=None):
        """
        Method to parse an individual requested module returned from the Yahoo Finance API call.
        :param modules_dict: A dictionary containing all the modules.
        :type modules_dict: dict
        :param module_name: The name of the module to be parsed.
        :type module_name: str
        :param submodule_name: The name of the submodule to be parsed. Some modules are wrapped in another dictionary.
        :type submodule_name: str
        :return: A tuple containing a dataframe containing the information and None, or None and an error.
        :rtype: tuple
        """

        # Attempt to find the module to be parsed. If the module is not found, then it will return None and a
        # YahooModuleNotFoundError.
        try:
            # Checks to see if there is a submodule.
            if not submodule_name:
                module = modules_dict[module_name]
            else:
                module = modules_dict[module_name][submodule_name]

        except Exception as e:
            return None, YahooExceptions.YahooModuleNotFoundError(e)

        # Attempt to get a formatted dataframe from the module. If there was an error formatting the dataframe, then it
        # will return None and a YahooModuleFormatError.
        try:
            module_dataframe = self._format_dataframe(module)

        except Exception as e:
            return None, YahooExceptions.YahooModuleFormatError(e)

        # If the module was found and formatted, then it will return a dataframe containing the module information and
        # None since there was no error.
        return module_dataframe, None