Exemple #1
0
    def execute(self, page, uid, pa_id, gid=None):
        scanlog("Scan: %s (group: %s)" % (
            pa_id,
            gid,
        ))
        page = decode(page)

        m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        if not m:
            scanlog("Expired/non-matchinng scan (id: %s)" % (pa_id, ))
            return

        scantype = m.group(1)[0].upper()
        x = int(m.group(2))
        y = int(m.group(3))
        z = int(m.group(4))
        tick = int(m.group(5))

        m = re.search("<p class=\"right scan_time\">Scan time: ([^<]*)</p>",
                      page)
        scantime = m.group(1)

        planet = PlanetHistory.load(x, y, z, tick).current
        if planet is None:
            return
        try:
            scan = Scan(pa_id=pa_id,
                        scantype=scantype,
                        tick=tick,
                        time=scantime,
                        group_id=gid,
                        scanner_id=uid)
            planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" % (
                pa_id,
                str(e),
            ))
            return
Exemple #2
0
    def parse_N(self, scan_id, scan, page):
        #incoming fleets
        #<td class=left valign=top>Incoming</td><td valign=top>851</td><td class=left valign=top>We have detected an open jumpgate from Tertiary, located at 18:5:11. The fleet will approach our system in tick 855 and appears to have roughly 95 ships.</td>
        for m in re.finditer(
                '<td class="left" valign="top">Incoming</td><td valign="top">(\d+)</td><td class="left" valign="top">We have detected an open jumpgate from ([^<]+), located at <a[^>]+>(\d+):(\d+):(\d+)</a>. The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.</td>',
                page):
            fleetscan = FleetScan()

            newstick = m.group(1)
            fleetname = m.group(2)
            originx = m.group(3)
            originy = m.group(4)
            originz = m.group(5)
            arrivaltick = m.group(6)
            numships = m.group(7)

            fleetscan.mission = "Unknown"
            fleetscan.fleet_name = fleetname
            fleetscan.launch_tick = newstick
            fleetscan.landing_tick = int(arrivaltick)
            fleetscan.fleet_size = numships

            owner = PlanetHistory.load(originx, originy, originz,
                                       newstick).current
            if owner is None:
                continue
            fleetscan.owner = owner
            fleetscan.target = scan.planet
            fleetscan.in_cluster = fleetscan.owner.x == fleetscan.target.x
            fleetscan.in_galaxy = fleetscan.in_cluster and fleetscan.owner.y == fleetscan.target.y

            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except Exception, e:
                session.rollback()
                scanlog("Exception in news: %s" % (str(e), ), traceback=True)
                continue

            scanlog('Incoming: ' + newstick + ':' + fleetname + '-' + originx +
                    ':' + originy + ':' + originz + '-' + arrivaltick + '|' +
                    numships)
Exemple #3
0
                page):
            fleetscan = FleetScan()

            newstick = m.group(1)
            fleetname = m.group(2)
            originx = m.group(3)
            originy = m.group(4)
            originz = m.group(5)
            arrivaltick = m.group(6)

            fleetscan.mission = "Attack"
            fleetscan.fleet_name = fleetname
            fleetscan.launch_tick = newstick
            fleetscan.landing_tick = arrivaltick

            target = PlanetHistory.load(originx, originy, originz,
                                        newstick).current
            if target is None:
                continue
            fleetscan.owner = scan.planet
            fleetscan.target = target
            fleetscan.in_cluster = fleetscan.owner.x == fleetscan.target.x
            fleetscan.in_galaxy = fleetscan.in_cluster and fleetscan.owner.y == fleetscan.target.y

            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except Exception, e:
                session.rollback()
                scanlog("Exception in news: %s" % (str(e), ), traceback=True)
                continue