Ejemplo n.º 1
0
    def name_and_create_dir(self, analytics_dir, args, scrape_file):
        """
        Name the new file and create the analytics directory.

        Calls public methods from external modules:

            GetPath.name_file()

        Parameters
        ----------
        analytics_dir: str
            String denoting the path to the directory in which the analytical
            data will be written
        args: Namespace
            Namespace object containing all arguments used in the CLI
        scrape_file: list
            List containing scrape files and file formats to generate wordcloud with

        Returns
        -------
        f_type: str
            String denoting the file format
        filename: str
            String denoting the filename
        """

        f_type = "csv" \
            if args.csv \
            else "json"

        filename = GetPath.name_file(analytics_dir, scrape_file[0])

        return f_type, filename
Ejemplo n.º 2
0
    def name_and_create_dir(self, args, file):
        """
        Name the new file and create the analytics directory.

        Calls public methods from external modules:

            GetPath.name_file()
            InitializeDirectory.make_analytics_directory(

        Parameters
        ----------
        args: Namespace
            Namespace object containing all arguments used in the CLI
        file: list
            List containing scrape files and file formats to generate wordcloud with

        Returns
        -------
        f_type: str
            String denoting the file format
        filename: str
            String denoting the filename
        """

        f_type = "csv" \
            if args.csv \
            else "json"

        date_dir, filename = GetPath.name_file(f_type, file[0], "frequencies")
        InitializeDirectory.make_analytics_directory(date_dir, "frequencies")

        return f_type, filename
Ejemplo n.º 3
0
    def get_data(self, scrape_file):
        """
        Get data from scrape file.

        Calls public methods from external modules:

            GetPath.get_scrape_type()
            PrepData.prep()

        Parameters
        ----------
        scrape_file: list
            List containing scrape files and file formats to generate wordcloud with

        Returns
        -------
        analytics_dir: str
            String denoting the path to the directory in which the analytical
            data will be written
        frequency_data: dict
            Dictionary containing extracted scrape data
        """

        analytics_dir, scrape_type = GetPath.get_scrape_type(
            scrape_file[0], "frequencies")

        return analytics_dir, PrepData.prep(scrape_file[0], scrape_type)
Ejemplo n.º 4
0
    def save_wordcloud(self, analytics_dir, scrape_file, wc):
        """
        Save wordcloud to file.

        Calls a public method from an external module:

            GetPath.name_file()

        Parameters
        ----------
        analytics_dir: str
            String denoting the path to the directory in which the analytical
            data will be written
        scrape_file: list
            List containing scrape files and file formats to generate wordcloud with
        wc: WordCloud
            Wordcloud instance

        Returns
        -------
        new_filename: str
            String denoting the filename for the exported wordcloud
        """

        filename = GetPath.name_file(analytics_dir, scrape_file[0])

        split_path = list(Path(filename).parts)

        split_filename = split_path[-1].split(".")
        split_filename[-1] = scrape_file[-1]

        split_path[-1] = ".".join(split_filename)
        new_filename = "/".join(split_path)

        export_status = Status(
            Style.BRIGHT + Fore.GREEN + f"Wordcloud exported to {new_filename}.",
            "Exporting wordcloud.",
            "white"
        )

        export_status.start()
        wc.to_file(new_filename)
        export_status.succeed()
        print()
        
        return new_filename
Ejemplo n.º 5
0
    def generate(args):
        """
        Generate wordcloud.

        Calls previously defined public methods:

            FinalizeWordcloud().show_wordcloud()
            FinalizeWordcloud().save_wordcloud()
            SetUpWordcloud.initialize_wordcloud()
            SetUpWordcloud.modify_wordcloud()

        Calls public methods from external modules:

            AnalyticsTitles.wc_title()
            GetPath.get_scrape_type()
        
        Parameters
        ----------
        args: Namespace
            Namespace object containing all arguments used in the CLI

        Returns
        -------
        None
        """

        AnalyticsTitles.wc_title()

        for file in args.wordcloud:
            scrape_type = GetPath.get_scrape_type(file[0])
            
            wc = SetUpWordcloud.initialize_wordcloud(file, scrape_type)
            
            Halo().info("Generating wordcloud.")
            print()
            plt = SetUpWordcloud.modify_wordcloud(wc)
            
            FinalizeWordcloud().show_wordcloud(plt) \
                if args.nosave \
                else FinalizeWordcloud().save_wordcloud(file, wc)
Ejemplo n.º 6
0
    def get_data(self, file):
        """
        Get data from scrape file.

        Calls public methods from external modules:

            GetPath.get_scrape_type()
            PrepData.prep()

        Parameters
        ----------
        file: list
            List containing scrape files and file formats to generate wordcloud with

        Returns
        -------
        frequency_data: dict
            Dictionary containing extracted scrape data
        """

        scrape_type = GetPath.get_scrape_type(file[0])
        return PrepData.prep(file[0], scrape_type)
Ejemplo n.º 7
0
    def save_wordcloud(self, file, wc):
        """
        Save wordcloud to file.

        Calls public methods from external modules:

            GetPath.name_file()
            InitializeDirectory.make_analytics_directory()

        Parameters
        ----------
        file: list
            List containing scrape files and file formats to generate wordcloud with
        wc: WordCloud
            Wordcloud instance

        Returns
        -------
        filename: str
            String denoting the filename for the exported wordcloud
        """

        date_dir, filename = GetPath.name_file(file[1], file[0], "wordclouds")
        
        export_status = Status(
            Style.BRIGHT + Fore.GREEN + "Wordcloud exported to %s." % "/".join(filename.split("/")[filename.split("/").index("scrapes"):]),
            "Exporting wordcloud.",
            "white"
        )

        export_status.start()
        InitializeDirectory.make_analytics_directory(date_dir, "wordclouds")
        wc.to_file(filename)
        export_status.succeed()
        print()
        
        return filename