def parse_J(self, scan_id, scan, page): # <td class=left>Origin</td><td class=left>Mission</td><td>Fleet</td><td>ETA</td><td>Fleetsize</td> # <td class=left>13:10:5</td><td class=left>Attack</td><td>Gamma</td><td>5</td><td>265</td> # <td class="left">15:7:11 </td><td class="left">Defend </td><td>Ad infinitum</td><td>9</td><td>0</td> #<tr><td class="left">10:4:9</td><td class="left">Return</td><td>They look thirsty</td><td>5</td><td>3000</td></tr> # <tr><td class="left">4:1:10</td><td class="left">Return</td><td>Or Is It?</td><td>9</td><td>3000</td></tr> #<tr><td class="left">10:1:10</td><td class="left">Defend</td><td class="left">Pesticide IV</td><td class="right">1</td><td class="right">0</td></tr> for m in re.finditer('<td[^>]*>(?:<a[^>]+>)?(\d+)\:(\d+)\:(\d+)(?:</a>)?[^/]*/[^/]*/td><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td><td[^>]*>(\d+)</td><td[^>]*>(\d+(?:,\d{3})*)</td>', page): scanlog("%s:%s:%s %s %s %s %s" %m.groups()) fleetscan = FleetScan() originx = m.group(1) originy = m.group(2) originz = m.group(3) mission = m.group(4) fleet = m.group(5) eta = int(m.group(6)) fleetsize = m.group(7).replace(',', '') fleetscan.mission = mission fleetscan.fleet_name = fleet fleetscan.landing_tick = eta + scan.tick fleetscan.fleet_size = fleetsize attacker=PlanetHistory.load_planet(originx,originy,originz,scan.tick) if attacker is None: scanlog("Can't find attacker in db: %s:%s:%s tick: %s"%(originx,originy,originz, scan.tick)) continue fleetscan.owner = attacker 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 IntegrityError, e: session.rollback() scanlog("Caught integrity exception in jgp: %s"%(str(e),)) scanlog("Trying to update instead") query = session.query(FleetScan).filter_by(owner=attacker, target=scan.planet, fleet_size=fleetsize, fleet_name=fleet, landing_tick=eta+scan.tick, mission=mission) try: query.update({"scan_id": scan_id}) session.commit() except Exception, e: session.rollback() scanlog("Exception trying to update jgp: %s"%(str(e),), traceback=True) continue
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_planet( originx, originy, originz, newstick, closest=not Config.getboolean("Misc", "catchup")) 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)
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
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_planet(originx,originy,originz,newstick,closest=not Config.getboolean("Misc", "catchup")) 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)
def parse_J(self, scan_id, scan, page): # <td class=left>Origin</td><td class=left>Mission</td><td>Fleet</td><td>ETA</td><td>Fleetsize</td> # <td class=left>13:10:5</td><td class=left>Attack</td><td>Gamma</td><td>5</td><td>265</td> # <td class="left">15:7:11 </td><td class="left">Defend </td><td>Ad infinitum</td><td>9</td><td>0</td> #<tr><td class="left">10:4:9</td><td class="left">Return</td><td>They look thirsty</td><td>5</td><td>3000</td></tr> # <tr><td class="left">4:1:10</td><td class="left">Return</td><td>Or Is It?</td><td>9</td><td>3000</td></tr> #<tr><td class="left">10:1:10</td><td class="left">Defend</td><td class="left">Pesticide IV</td><td class="right">1</td><td class="right">0</td></tr> for m in re.finditer( '<td[^>]*>(?:<a[^>]+>)?(\d+)\:(\d+)\:(\d+)(?:</a>)?[^/]*/[^/]*/td><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td><td[^>]*>(\d+)</td><td[^>]*>(\d+(?:,\d{3})*)</td>', page): scanlog("%s:%s:%s %s %s %s %s" % m.groups()) fleetscan = FleetScan() originx = m.group(1) originy = m.group(2) originz = m.group(3) mission = m.group(4) fleet = m.group(5) eta = int(m.group(6)) fleetsize = m.group(7).replace(',', '') fleetscan.mission = mission fleetscan.fleet_name = fleet fleetscan.landing_tick = eta + scan.tick fleetscan.fleet_size = fleetsize attacker = PlanetHistory.load_planet(originx, originy, originz, scan.tick) if attacker is None: scanlog("Can't find attacker in db: %s:%s:%s tick: %s" % (originx, originy, originz, scan.tick)) continue fleetscan.owner = attacker 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 IntegrityError, e: session.rollback() scanlog("Caught integrity exception in jgp: %s" % (str(e), )) scanlog("Trying to update instead") query = session.query(FleetScan).filter_by( owner=attacker, target=scan.planet, fleet_size=fleetsize, fleet_name=fleet, landing_tick=eta + scan.tick, mission=mission) try: query.update({"scan_id": scan_id}) session.commit() except Exception, e: session.rollback() scanlog("Exception trying to update jgp: %s" % (str(e), ), traceback=True) continue
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_planet( originx, originy, originz, newstick, closest=not Config.getboolean("Misc", "catchup")) 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)
for m in re.finditer('<td class="left" valign="top">Launch</td><td valign="top">(\d+)</td><td class="left" valign="top">The ([^,]+) fleet has been launched, heading for <a[^>]+>(\d+):(\d+):(\d+)</a>, on a mission to Attack. Arrival tick: (\d+)</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) fleetscan.mission = "Attack" fleetscan.fleet_name = fleetname fleetscan.launch_tick = newstick fleetscan.landing_tick = arrivaltick target = PlanetHistory.load_planet(originx,originy,originz,newstick,closest=not Config.getboolean("Misc", "catchup")) 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
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