Esempio n. 1
0
    def get_fleet(self):
        fleets_list = []
        response = self.session.get(
            'https://s{}-{}.ogame.gameforge.com/game/index.php?'
            'page=componentOnly&component=eventList&action=fetchEventBox&ajax=1&asJson=1'
            .format(self.server_number, self.server_language)).json()
        if response['friendly'] != 0:
            response = self.session.get(
                'https://s{}-{}.ogame.gameforge.com/game/index.php?page=ingame&'
                'component=movement'.format(self.server_number,
                                            self.server_language)).text
            fleets = response.split('<div id="fleet')
            del fleets[0]
            for fleet in fleets:
                fleet_id = fleet[0:30].split('"')[0]
                marker = fleet.find('data-mission-type="')
                fleet_mission = int(fleet[marker + 19:marker +
                                          22].split('"')[0])
                if 'data-return-flight="1"' in fleet:
                    fleet_return = True
                else:
                    fleet_return = False
                marker = fleet.find('<span class="timer tooltip" title="')
                fleet_arrival = datetime.strptime(
                    fleet[marker + 35:marker + 54], '%d.%m.%Y %H:%M:%S')
                marker = fleet.find(
                    '<span class="originCoords tooltip" title="')
                origin_raw = fleet[marker:marker + 180]
                origin_list = origin_raw.split('[')[1].split(']')[0].split(':')
                fleet_origin = const.coordinates(origin_list[0],
                                                 origin_list[1],
                                                 origin_list[2])
                marker = fleet.find('<span class="destinationCoords tooltip"')
                destination_raw = fleet[marker:marker + 200]
                destination_list = destination_raw.split('[')[1].split(
                    ']')[0].split(':')
                fleet_destination = const.coordinates(destination_list[0],
                                                      destination_list[1],
                                                      destination_list[2])

                class fleets_class:
                    id = fleet_id
                    mission = fleet_mission
                    returns = fleet_return
                    arrival = fleet_arrival
                    origin = fleet_origin
                    destination = fleet_destination
                    list = [
                        fleet_id, fleet_mission, fleet_return, fleet_arrival,
                        fleet_origin, fleet_destination
                    ]

                fleets_list.append(fleets_class)
            return fleets_list
        else:
            return fleets_list
Esempio n. 2
0
    def get_phalanx(self, coordinates, id):
        response = self.session.get(
            'https://s{}-{}.ogame.gameforge.com/game/index.php?'
            'page=phalanx&galaxy={}&system={}&position={}&ajax=1&cp={}'.format(
                self.server_number, self.server_language, coordinates[0],
                coordinates[1], coordinates[2], id)).text
        fleets_list = []
        fleets = response.split('<div class="eventFleet" id="eventRow-')
        del fleets[0]
        for fleet in fleets:
            fleet_id = fleet[0:30].split('"')[0]
            marker = fleet.find('data-mission-type="')
            fleet_mission = int(fleet[marker + 19:marker + 22].split('"')[0])
            if 'data-return-flight="true"' in fleet:
                fleet_return = True
            else:
                fleet_return = False
            marker = fleet.find('<li class="arrivalTime">')
            fleet_arrival = datetime.combine(
                datetime.today(),
                datetime.strptime(fleet[marker + 24:marker + 32],
                                  '%H:%M:%S').time())
            marker = fleet.find('<li class="coordsOrigin">')
            origin_raw = fleet[marker:marker + 230]
            origin_list = origin_raw.split('[')[1].split(']')[0].split(':')
            fleet_origin = const.coordinates(origin_list[0], origin_list[1],
                                             origin_list[2])
            marker = fleet.find('<li class="destCoords">')
            destination_raw = fleet[marker:marker + 250]
            destination_list = destination_raw.split('[')[1].split(
                ']')[0].split(':')
            fleet_destination = const.coordinates(destination_list[0],
                                                  destination_list[1],
                                                  destination_list[2])

            class fleets_class:
                id = fleet_id
                mission = fleet_mission
                returns = fleet_return
                arrival = fleet_arrival
                origin = fleet_origin
                destination = fleet_destination
                list = [
                    fleet_id, fleet_mission, fleet_return, fleet_arrival,
                    fleet_origin, fleet_destination
                ]

            fleets_list.append(fleets_class)
        return fleets_list
Esempio n. 3
0
 class planet_class:
     position = const.coordinates(coordinates[0], coordinates[1], planet_pos)
     name = planet_name
     player = planet_player
     player_id = planet_player_id
     status = planet_status
     if planet_pos in moons:
         moon = True
     else:
         moon = False
     list = [name, position, player, player_id, status, moon]
Esempio n. 4
0
    def galaxy_debris(self, coords):
        response = self.session.post(
            url=self.index_php + 'page=ingame&component=galaxyContent&ajax=1',
            data={'galaxy': coords[0], 'system': coords[1]},
            headers={'X-Requested-With': 'XMLHttpRequest'}
        ).json()
        bs4 = BeautifulSoup4(response['galaxy'])
        debris_fields = []
        debris_rows = bs4.find_all('td', {'class': 'debris'})
        for row in debris_rows:
            debris = True
            row['class'].remove('debris')
            if 'js_no_action' in row['class']:
                debris = False
                row['class'].remove('js_no_action')
            debris_cord = int(row['class'][0].replace('js_debris', ''))
            debris_cord = const.coordinates(
                coords[0],
                coords[1],
                int(debris_cord), const.destination.debris
            )
            debris_resources = [0, 0, 0]
            if debris:
                debris_resources = row.find_all('li', {'class': 'debris-content'})
                debris_resources = [
                    int(debris_resources[0].text.split(':')[1].replace('.','')),
                    int(debris_resources[1].text.split(':')[1].replace('.','')),
                    0
                ]

            class Position:
                position = debris_cord
                has_debris = debris
                resources = debris_resources
                metal = resources[0]
                crystal = resources[1]
                deuterium = resources[2]
                list = [
                    position, has_debris, resources,
                    metal, crystal, deuterium
                ]
            if len(coords) >= 3 and coords[2] == Position.position[2]:
                return Position
            debris_fields.append(Position)
        return debris_fields
Esempio n. 5
0
 class planet_class:
     planet_name = planet.split('<h1>Planet:')[1][26:50].split(
         '<')[0]
     coordinates = const.coordinates(int(coordinates_raw[0]),
                                     int(coordinates_raw[1]),
                                     int(coordinates_raw[2]))
     player = None
     status = None
     if '<span class="status_abbr_active">' in planet:
         player = planet.split(
             '<span class="status_abbr_active">')[1].split('<')[0]
         status = 'active'
     if '<span class="status_abbr_inactive">' in planet:
         player = planet.split(
             '<span class="status_abbr_inactive">')[1].split('<')[0]
         status = 'inactive'
     elif '<span class="status_abbr_longinactive">' in planet:
         player = planet.split(
             '<span class="status_abbr_longinactive">')[1].split(
                 '<')[0]
         status = 'longinactive'
     elif '<span class="status_abbr_vacation">' in planet:
         player = planet.split(
             '<span class="status_abbr_vacation">')[1].split('<')[0]
         status = 'vacation'
     elif '<span class="status_abbr_admin">' in planet:
         player = planet.split(
             '<span class="status_abbr_admin">')[1].split('<')[0]
         status = 'admin'
     elif '<span class="status_abbr_honorableTarget">' in planet:
         player = planet.split(
             '<span class="status_abbr_honorableTarget">')[1].split(
                 '<')[0]
         status = 'honorableTarget'
     elif '<span class="status_abbr_noob">' in planet:
         player = planet.split(
             '<span class="status_abbr_noob">')[1].split('<')[0]
         status = 'noob'
     if '<div class="moon_a"' in planet:
         moon = True
     else:
         moon = False
     list = [planet_name, coordinates, player, status, moon]
Esempio n. 6
0
    def galaxy(self, coords):
        response = self.session.post(
            url=self.index_php + 'page=ingame&component=galaxyContent&ajax=1',
            data={
                'galaxy': coords[0],
                'system': coords[1]
            },
            headers={
                'X-Requested-With': 'XMLHttpRequest'
            }).json()
        bs4 = self.BS4(response['galaxy'])

        def num_from_tag(tag):
            """ 'player123' -> 123 """
            numbers = re.search(r'[0-9]+', tag).group()
            return int(numbers) if numbers else None

        players = bs4.find_all_partial(id='player')
        player_name = {
            num_from_tag(player['id']): player.h1.span.text
            for player in players
        }
        player_rank = {
            num_from_tag(player['id']): int(player.a.text)
            for player in players if player.a.text.isdigit()
        }

        alliances = bs4.find_all_partial(id='alliance')
        alliance_name = {
            num_from_tag(alliance['id']): alliance.h1.text.strip()
            for alliance in alliances
        }

        planets = []
        for row in bs4.select('#galaxytable .row'):
            status = row['class']
            status.remove('row')
            if 'empty_filter' in status:
                continue

            if len(status) == 0:
                planet_status = [const.status.yourself]
                pid = self.player_id
                player_name[pid] = self.player
            else:
                planet_status = [
                    re.search('(.*)_filter', sta).group(1) for sta in status
                ]

                player = row.find(rel=re.compile(r'player[0-9]+'))
                if not player:
                    continue
                pid = num_from_tag(player['rel'][0])
                if pid == 99999:
                    # Destroyed Planet
                    continue

            planet = int(row.find(class_='position').text)
            planet_cord = const.coordinates(coords[0], coords[1], int(planet),
                                            const.destination.planet)
            moon_pos = row.find(rel=re.compile(r'moon[0-9]*'))

            alliance_id = row.find(rel=re.compile(r'alliance[0-9]+'))
            alliance_id = num_from_tag(
                alliance_id['rel']) if alliance_id else None

            class Position:
                position = planet_cord
                name = row.find(id=re.compile(r'planet[0-9]+')).h1.span.text
                player = player_name[pid]
                player_id = pid
                rank = player_rank.get(pid)
                status = planet_status
                moon = moon_pos is not None
                alliance = alliance_name.get(alliance_id)
                list = [
                    name, position, player, player_id, rank, status, moon,
                    alliance
                ]

            planets.append(Position)

        return planets
Esempio n. 7
0
    def galaxy(self, coords):
        response = self.session.post(
            url=self.index_php + 'page=ingame&component=galaxyContent&ajax=1',
            data={
                'galaxy': coords[0],
                'system': coords[1]
            },
            headers={
                'X-Requested-With': 'XMLHttpRequest'
            }).json()
        bs4 = self.BS4(response['galaxy'])

        positions = bs4.find_all_partial(rel='planet')
        positions = [pos['rel'] for pos in positions]
        positions = [
            re.search('planet(.*)', pos).group(1) for pos in positions
        ]
        positions = [
            const.coordinates(coords[0], coords[1], int(pos),
                              const.destination.planet) for pos in positions
        ]

        planet_names = bs4.find_all_partial(rel='planet')
        planet_names = [name.h1.span.text for name in planet_names]

        players = bs4.find_all_partial(id='player')
        player_names = [name.h1.span.text for name in players]
        player_ids = [id['id'] for id in players]
        player_ids = [
            int(re.search('player(.*)', id).group(1)) for id in player_ids
        ]

        planet_status = []
        for status in bs4.find_all(class_='row'):
            status = status['class']
            status.remove('row')
            if 'empty_filter' in status:
                continue
            elif len(status) is 0:
                planet_status.append([const.status.yourself])
            else:
                status = [
                    re.search('(.*)_filter', sta).group(1) for sta in status
                ]
                planet_status.append(status)

        moon_pos = bs4.find_all_partial(rel='moon')
        moon_pos = [pos['rel'] for pos in moon_pos]
        moon_pos = [
            int(re.search('moon(.*)', pos).group(1)) for pos in moon_pos
        ]

        planets = []
        for i in range(len(player_ids)):

            class Position:
                position = positions[i]
                name = planet_names[i]
                player = player_names[i]
                player_id = player_ids[i]
                status = planet_status[i]
                if position[2] in moon_pos:
                    moon = True
                else:
                    moon = False
                list = [name, position, player, player_id, status, moon]

            planets.append(Position)

        return planets