def execute(self, message, user, params): num, name, attacker = params.groups() attacker = (attacker or "t1").lower() num = self.short2num(num) ship = Ship.load(name=name) if ship is not None: pass elif "asteroids".rfind(name.lower()) > -1: ship = Ship(name="Asteroids", class_="Roids", armor=50, total_cost=PA.getint("numbers", "roid_value") * PA.getint("numbers", "ship_value")) elif "constructions".rfind(name.lower()) > -1: ship = Ship(name="Constructions", class_="Struct", armor=500, total_cost=PA.getint("numbers", "cons_value") * PA.getint("numbers", "ship_value")) else: message.alert("No Ship called: %s" % (name, )) return efficiency = PA.getfloat("teffs", attacker.lower()) attacker_class = getattr(Ship, attacker) attackers = session.query(Ship).filter(attacker_class == ship.class_) if attackers.count() == 0: message.reply("%s are not hit by anything as that category (%s)" % (ship.name, attacker)) return if ship.class_ == "Roids": reply = "Capturing" elif ship.class_ == "Struct": reply = "Destroying" else: reply = "Stopping" reply += " %s %s (%s) as %s requires " % ( num, ship.name, self.num2short(num * ship.total_cost / PA.getint("numbers", "ship_value")), attacker) for attacker in attackers: if attacker.type.lower() == "emp": needed = int((math.ceil( num / (float(100 - ship.empres) / 100) / attacker.guns)) / efficiency) else: needed = int( (math.ceil(float(ship.armor * num) / attacker.damage)) / efficiency) reply += "%s: %s (%s) " % (attacker.name, needed, self.num2short( attacker.total_cost * needed / PA.getint("numbers", "ship_value"))) message.reply(reply)
def main(url=Config.get("URL", "ships"), debug=False): stats = urllib2.urlopen(url).read() session.execute(Ship.__table__.delete()) session.execute( text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false])) for line in sre.findall(stats): ship = Ship() line = list(line) for index, key in enumerate(keys): if line[index] in mapping: line[index] = mapping[line[index]] elif line[index].isdigit(): line[index] = int(line[index]) if line[index] not in ( '-', '', ): setattr(ship, key, line[index]) ship.total_cost = ship.metal + ship.crystal + ship.eonium if debug: print "%12s%12s%12s%12s" % ( ship.name, ship.class_, ship.race, ship.type, ) session.add(ship) session.commit() session.close()
def main(url=Config.get("URL", "ships"), debug=False): req = urllib2.Request(url) req.add_header('User-Agent', useragent) stats = urllib2.urlopen(req).read() session.execute(Ship.__table__.delete()) if Config.get("DB", "dbms") == "mysql": session.execute( text("ALTER TABLE ships AUTO_INCREMENT=1;", bindparams=[false])) else: session.execute( text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false])) for line in sre.findall(stats): ship = Ship() line = list(line) for index, key in enumerate(keys): if line[index] in mapping: line[index] = mapping[line[index]] elif line[index].isdigit(): line[index] = int(line[index]) if line[index] not in ( '-', '', ): setattr(ship, key, line[index]) ship.total_cost = ship.metal + ship.crystal + ship.eonium if debug: print "%12s%12s%12s%12s" % ( ship.name, ship.class_, ship.race, ship.type, ) session.add(ship) session.commit() session.close()
def add_ship(dct): ship = Ship() for key in dct.keys(): if dct[key] != "-": if key == "class": k = key + "_" elif key[:4] == "init": k = "init" elif key[:6] == "target": k = "t" + key[-1] else: k = key setattr(ship, k, dct[key]) ship.total_cost = int(ship.metal) + int(ship.crystal) + int(ship.eonium) session.add(ship) if __name__ == '__main__': print "%12s%12s%12s%12s" % ( ship.name, ship.class_, ship.race, ship.type, )