Exemple #1
0
    def update_player_prices(self, queue=None, console="PS4"):
        """
        Gets updated price information for all the players on the list/db
        Input: None
        Output: None  -  the player price information is updated
        """

        # Iterate through player list and get updated prices
        total_players = len(self.db)
        for idx, player_info in enumerate(self.db):
            player = Player(player_info)
            self.db[idx]["price"] = player.get_price(console)

            # Display number of pages completed
            if queue is not None:
                queue.put((idx + 1, total_players))
            print "%d of %d players updated" % (idx + 1, total_players)
 def __init__(self, client, address, db):
     super().__init__()
     self.client = client
     self.address = address
     self.db = db
     self.config = json.loads(open('config.json', 'r').read())
     self.device = Device(self.client)
     self.player = Player(self.device)
Exemple #3
0
    def __init__(self, mode='Play', replay_moves=None, patch=PATCH):
        """ Set up players, variables, and start the game! """
        # Make objects
        player1_name = '1'
        player2_name = '2'
        self.player1 = Player(
            0, player1_name
        )  # Make first player, parameter is the name of the player
        self.player2 = Player(1, player2_name)  # Make second player
        self.field = Field()  # Make field

        # Place for variables
        self.mode = mode
        self.patch = patch
        if self.patch != PATCH:
            self.patch_info = dict()
            self.fill_patch_info()
        else:
            self.patch_info = CARDS
        self.active_player = self.player1
        if mode == 'Play':
            self.moves = list(
            )  # Make list to store all played moves for replay
        self.actions = dict()  # Make dictionary for all available commands
        self.actions_replay = dict()
        self.playing = True
        self.open = True
        self.note = None  # Variable for message sent to user
        if replay_moves is not None:
            self.replay_moves = replay_moves
            self.line = 1

        # Initialization functions
        self.set_available_inputs()  # Set all commands
        self.set_field_player()  # Connect field to the correct player

        # Game loop
        self.loop()  # Start the game
Exemple #4
0
 def __init__(self, data, device):
     super().__init__(data)
     self.device = device
     self.player = Player(device)
Exemple #5
0
    def download(self, queue=None, get_prices=True, console="PLAYSTATION"):
        """
        Download the database from the EA FIFA website
        Input: None
        Output: The downloaded database which is also already saved in the object
        """

        url_db_start = 'https://www.easports.com/fifa/ultimate-team/api/fut/item?jsonParamObject={"page":"'
        url_db_end = '"}'
        del self.db[:]  # Empty existing DB list
        players_found = []

        try:
            # Create session
            sess = requests.Session()

            # Get total number of pages of data
            page_data = sess.get("%s1%s" % (url_db_start, url_db_end), verify=False).content  # Get first page data
            total_pages = json.loads(page_data)["totalPages"]  # Get total number of pages

            # Iterate through all pages
            for page_num in range(1, total_pages + 1):
                while True:
                    try:
                        # Get first page data
                        page_data = json.loads(sess.get("%s%s%s" % (url_db_start, page_num, url_db_end)).content)
                        break
                    except Exception:
                        print "JSON Loading Error. Retrying Load."

                # Get the number of players on the page
                total_players = page_data["count"]

                # Iterate through players on page
                for player_num in range(total_players):
                    # Get player data and create player
                    player_data = page_data["items"][player_num]
                    temp_player = Player(player_data)

                    # If player is a legend and console is PS4, skip
                    if console == "PLAYSTATION" and temp_player.playerType.lower() == "legend":
                        continue

                    # Add player to database and avoid duplicates
                    if players_found.count(temp_player.id) == 0:
                        if get_prices:
                            temp_player.get_price(console)
                        self.db.append(temp_player.__dict__)
                        players_found.append(Player(player_data).id)

                # Display number of pages completed
                if queue is not None:
                    queue.put((page_num, total_pages))
                print "%d of %d pages downloaded" % (page_num, total_pages)

        except requests.ConnectionError:
            print "Not connected to Internet. Cannot download player db."
            queue.put(("Not connected to Internet. Cannot download player db.",))

        except Exception as err:
            print err.__str__()
            queue.put((err.__str__(),))

        return self.db
Exemple #6
0
 def __init__(self, client, address):
     super().__init__()
     self.client = client
     self.address = address
     self.device = Device(self.client)
     self.player = Player(self.device)
 def __init__(self, client, addr):
     super().__init__()
     self.client = client
     self.addr = addr
     self.crypto = NaCl()
     self.player = Player()