Ejemplo n.º 1
0
    def retrieve_summoner_info(self, queue, name, region):
        """
        This function tells the api_methods to collect information from the internet and return them to here. After
        that, basic data manipulation occurs and then it is sent to the queue for the app to manage
        :param name:
        :param region:
        :return:
        """

        # Set the name to the one specified by the user
        self.name = clean.clean(name)

        # Set the region to the one specified by the user
        self.region = region_data.get_region_by_slug(region)

        # Check if the name is valid
        [name_is_valid, reason] = verify.is_name_valid(self.name)

        # If the username is not valid...
        if not name_is_valid:
            # Update the status bar
            put_list = ["update status bar", reason, "red"]
            queue.put(put_list)
            return  # Exit the function

        # Update status bar
        put_list = ["update status bar", "Getting info...", "dark orange"]
        queue.put(put_list)

        # Obtain a summoner
        self.summoner, response = summoner_v1_4.get_summoner_by_name(self.api_key, self.name, self.region)

        # Update the version from the selected region
        self.versions = data_dragon.Versions(self.region)

        # If response is healthy...
        if response.status_code == 200:

            # Obtain the image
            summoner_icon = data_dragon.SummonerIcon(self.versions.profile_icon_version, self.summoner.profile_icon_id)

            # Save the image locally
            with open(summoner_icon.file, "wb") as f:
                for chunk in summoner_icon.response.iter_content(512):
                    f.write(chunk)

            # Send the updated information to the GUI
            put_list = ["update summoner data", str(self.summoner.level)]
            queue.put(put_list)

            # Update the status bar
            put_list = ["update status bar", "Obtained summoner: " + self.summoner.name, "green"]
            queue.put(put_list)

        # Otherwise...
        else:

            # Display reason in the status bar
            put_list = ["update status bar", response.reason, "red"]
            queue.put(put_list)
Ejemplo n.º 2
0
    def __init__(self):
        """
        Constructor for Model object
        :return:
        """

        # Riot developer API key
        self.api_key = "348d54f6-1599-431e-9fea-373ec5c65325"

        # Default summoner name the model uses
        self.name = ""

        # Default summoner for the user
        self.summoner = summoner.Summoner()

        # Default participants involved in current game
        self.participants = None

        # Default region the model uses (Explicitly Oceania)
        self.region = region_data.get_region_by_slug("oce")

        # Versions (version numbers for various requests and information)
        self.versions = None
Ejemplo n.º 3
0
    def __init__(self):
        """
        Constructor for Model object
        :return:
        """

        # Riot developer API key
        self.api_key = "348d54f6-1599-431e-9fea-373ec5c65325"

        # Default summoner name the model uses
        self.name = ""

        # Default summoner for the user
        self.summoner = summoner.Summoner()

        # Default participants involved in current game
        self.participants = None

        # Default region the model uses (Explicitly Oceania)
        self.region = region_data.get_region_by_slug('oce')

        # Versions (version numbers for various requests and information)
        self.versions = None
Ejemplo n.º 4
0
    def retrieve_summoner_info(self, queue, name, region):
        """
        This function tells the api_methods to collect information from the internet and return them to here. After
        that, basic data manipulation occurs and then it is sent to the queue for the app to manage
        :param name:
        :param region:
        :return:
        """

        # Set the name to the one specified by the user
        self.name = clean.clean(name)

        # Set the region to the one specified by the user
        self.region = region_data.get_region_by_slug(region)

        # Check if the name is valid
        [name_is_valid, reason] = verify.is_name_valid(self.name)

        # If the username is not valid...
        if not name_is_valid:
            # Update the status bar
            put_list = ["update status bar", reason, "red"]
            queue.put(put_list)
            return  # Exit the function

        # Update status bar
        put_list = ["update status bar", "Getting info...", "dark orange"]
        queue.put(put_list)

        # Obtain a summoner
        self.summoner, response = summoner_v1_4.get_summoner_by_name(
            self.api_key, self.name, self.region)

        # Update the version from the selected region
        self.versions = data_dragon.Versions(self.region)

        # If response is healthy...
        if response.status_code == 200:

            # Obtain the image
            summoner_icon = data_dragon.SummonerIcon(
                self.versions.profile_icon_version,
                self.summoner.profile_icon_id)

            # Save the image locally
            with open(summoner_icon.file, 'wb') as f:
                for chunk in summoner_icon.response.iter_content(512):
                    f.write(chunk)

            # Send the updated information to the GUI
            put_list = ["update summoner data", str(self.summoner.level)]
            queue.put(put_list)

            # Update the status bar
            put_list = [
                "update status bar",
                "Obtained summoner: " + self.summoner.name, "green"
            ]
            queue.put(put_list)

        # Otherwise...
        else:

            # Display reason in the status bar
            put_list = ["update status bar", response.reason, "red"]
            queue.put(put_list)