当前位置: 首页>>代码示例>>Python>>正文


Python maps.Updates类代码示例

本文整理汇总了Python中Core.maps.Updates的典型用法代码示例。如果您正苦于以下问题:Python Updates类的具体用法?Python Updates怎么用?Python Updates使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Updates类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tick

 def tick(self, message, user, params):
     tick = Updates.load(params.group(1)) or Updates.current_tick()
     if isinstance(tick, Updates): # We have that tick
         message.reply(str(tick))
     elif tick == 0:               # We don't have any ticks
         ticktime = GameSetup.getint("round_start_time") + (int(params.group(1))-1)*GameSetup.getint("tick_speed")
         tdiff = int(ticktime - time.time())
         tdelta = abs(tdiff / 86400)
         retstr  = " %sd" % tdelta if tdelta else ""
         tdelta = (tdiff % 86400) / 3600
         retstr += " %sh" % tdelta if tdelta else ""
         tdelta = (tdiff % 3600) / 60
         retstr += " %sm" % tdelta if tdelta else ""
         retstr = "Tick %s %s expected to happen%s%s%s - %s" % (params.group(1), "is" if tdiff >= 0 else "was", " in" if tdiff >= 0 else "", retstr, " ago" if tdiff < 0 else "", datetime.utcfromtimestamp(float(ticktime)).strftime("%a %d/%m %H:%M UTC"))
         message.reply(retstr)
     else:                         # We have some ticks, but not that one
         diff = int(params.group(1)) - tick
         now = datetime.utcnow()
         tick_speed = GameSetup.getint("tick_speed")
         tdiff = timedelta(seconds=tick_speed*diff)-timedelta(minutes=now.minute%(tick_speed/60))
         retstr  = "%sd " % abs(tdiff.days) if tdiff.days else ""
         retstr += "%sh " % abs(tdiff.seconds/3600) if tdiff.seconds/3600 else ""
         retstr += "%sm " % abs(tdiff.seconds%3600/60) if tdiff.seconds%3600/60 else ""
             
         if diff == 1:
             retstr = "Next tick is %s (in %s" % (params.group(1), retstr)
         elif diff > 1:
             retstr = "Tick %s is expected to happen in %s ticks (in %s" % (params.group(1), diff, retstr)
         elif diff <= 0:
             retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (params.group(1), -diff, retstr)
         
         ticktime = now + tdiff
         retstr += " - %s)" % (ticktime.strftime("%a %d/%m %H:%M UTC"),)
         message.reply(retstr)
开发者ID:berten,项目名称:merlin,代码行数:34,代码来源:tick.py

示例2: execute

    def execute(self, request, user, x, y, z, fleets):
        tick = Updates.midnight_tick()
        week = Updates.week_tick()

        planet = Planet.load(x, y, z)
        if planet is None:
            return HttpResponseRedirect(reverse("planet_ranks"))
        ph = planet.history(tick)

        Q = session.query(FleetScan, Planet, Alliance)
        Q = Q.join(FleetScan.target)
        Q = Q.outerjoin(Planet.intel).outerjoin(Intel.alliance)
        Q = Q.filter(FleetScan.owner == planet)
        Q = Q.order_by(desc(FleetScan.landing_tick))
        if not fleets:
            Q = Q.filter(FleetScan.landing_tick >= week)
        outgoing = Q.all()

        Q = session.query(FleetScan, Planet, Alliance)
        Q = Q.join(FleetScan.owner)
        Q = Q.outerjoin(Planet.intel).outerjoin(Intel.alliance)
        Q = Q.filter(FleetScan.target == planet)
        Q = Q.order_by(desc(FleetScan.landing_tick))
        if not fleets:
            Q = Q.filter(FleetScan.landing_tick >= week)
        incoming = Q.all()

        scan = planet.scan("A") or planet.scan("U")

        return render("planet.tpl", request, planet=planet, ph=ph, scan=scan, outgoing=outgoing, incoming=incoming)
开发者ID:munin,项目名称:merlin,代码行数:30,代码来源:planet.py

示例3: tick

    def tick(self, message, user, params):
        tick = Updates.load(params.group(1)) or Updates.current_tick()
        if tick is None:
            message.reply("Ticks haven't started yet, go back to masturbating.")
        elif isinstance(tick, Updates):
            message.reply(str(tick))
        else:
            diff = int(params.group(1)) - tick
            now = datetime.utcnow()
            tick_length = PA.getint("numbers", "tick_length")
            tdiff = timedelta(seconds=tick_length * diff) - timedelta(minutes=now.minute % (tick_length / 60))
            seconds = 0
            retstr = "%sd " % abs(tdiff.days) if tdiff.days else ""
            retstr += "%sh " % abs(tdiff.seconds / 3600) if tdiff.seconds / 3600 else ""
            retstr += "%sm " % abs(tdiff.seconds % 3600 / 60) if tdiff.seconds % 3600 / 60 else ""

            if diff == 1:
                retstr = "Next tick is %s (in %s" % (params.group(1), retstr)
            elif diff > 1:
                retstr = "Tick %s is expected to happen in %s ticks (in %s" % (params.group(1), diff, retstr)
            elif diff <= 0:
                retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (
                    params.group(1),
                    -diff,
                    retstr,
                )

            time = now + tdiff
            retstr += " - %s)" % (time.strftime("%a %d/%m %H:%M"),)
            message.reply(retstr)
开发者ID:liam-wiltshire,项目名称:merlin,代码行数:30,代码来源:tick.py

示例4: tick

 def tick(self, message, user, params):
     tick = Updates.load(params.group(1)) or Updates.current_tick()
     if tick is None:
         message.reply("Ticks haven't started yet, go back to masturbating.")
     elif isinstance(tick, Updates):
         message.reply(str(tick))
     else:
         diff = int(params.group(1)) - tick
         now = datetime.utcnow()
         seconds = 0
         retstr = ""
         if diff > 0:
             
             if diff > 24:
                 days = (diff-1)/24
                 seconds += days*24*60*60
                 retstr += "%sd " % (days,)
             
             if diff > 1:
                 hours = (diff-1)%24
                 seconds += hours*60*60
                 retstr += "%sh " % (hours,)
             
             mins = 60 - now.minute
             seconds += mins *60
             retstr += "%sm" % (mins,)
             
             if diff == 1:
                 retstr = "Next tick is %s (in %s" % (params.group(1), retstr,)
             else:
                 retstr = "Tick %s is expected to happen in %s ticks (in %s" % (params.group(1), diff, retstr,)
         
         elif diff < 0:
             
             if diff < -23:
                 days = (-diff)/24
                 seconds -= days*24*60*60
                 retstr += "%sd " % (days,)
                 
             if diff < -1:
                 hours = (-diff)%24
                 seconds -= hours*60*60
                 retstr += "%sh " % (hours,)
                 
             mins = now.minute
             seconds -= mins*60
             retstr += "%sm" % (mins,)
             
             if diff == -1:
                 retstr = "Last tick was %s (%s ago" % (params.group(1), retstr,)
             else:
                 retstr = "Tick %s was expected to happen %s ticks ago but was not scraped (%s ago" % (params.group(1), -diff, retstr,)
         
         time = now + timedelta(seconds=seconds)
         retstr += " - %s)" % (time.strftime("%a %d/%m %H:%M"),)
         message.reply(retstr)
开发者ID:Hardware-Hacks,项目名称:merlin,代码行数:56,代码来源:tick.py

示例5: list

 def list(self, message, user, params):
     Q = session.query(Attack)
     if user.access < (Config.getint("Access",  "hc") if "hc" in Config.options("Access") else 1000): # Hide attacks until they are active, unless the user has access
         Q = Q.filter(Attack.landtick <= Updates.current_tick() + Config.getint("Misc", "attactive"))
     Q = Q.filter(Attack.landtick + Attack.waves >= Updates.current_tick()) # Hide attacks one tick after the last wave has landed
     Q = Q.order_by(asc(Attack.id))
     
     replies = []
     for attack in Q:
         replies.append("(%d LT: %d %s)" %(attack.id,attack.landtick,attack.comment,))
     
     reply = "Open attacks: " + " ".join(replies)
     message.reply(reply)
开发者ID:JDD,项目名称:merlin,代码行数:13,代码来源:attack.py

示例6: land

 def land(self, message, user, params):
     id = int(params.group(1))
     attack = Attack.load(id)
     if attack is None:
         message.alert("No attack exists with id %d" %(id))
         return
     
     tick = Updates.current_tick()
     when = int(params.group(2))
     
     if when == 0:
         session.delete(attack)
         session.commit()
         message.reply("Deleted Attack %d LT: %d | %s" %(attack.id,attack.landtick,attack.comment,))
         return
     
     if when < PA.getint("numbers", "protection"):
         eta = when
         when += tick
     elif when <= tick:
         message.alert("Can not create attacks in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
         return
     else:
         eta = when - tick
     if when > 32767:
         when = 32767
     
     old = attack.landtick
     attack.landtick = when
     
     session.commit()
     message.reply("Changed LT for attack %d from %d to %d"%(id,old,when))
开发者ID:Hardware-Hacks,项目名称:merlin,代码行数:32,代码来源:editattack.py

示例7: execute

 def execute(self, request, user, page="1", sort="score", race="all"):
     page = int(page)
     offset = (page - 1)*50
     order =  {"score" : (asc(Planet.score_rank),),
               "value" : (asc(Planet.value_rank),),
               "size"  : (asc(Planet.size_rank),),
               "xp"    : (asc(Planet.xp_rank),),
               "race"  : (asc(Planet.race), asc(Planet.size_rank),),
               }
     if sort not in order.keys():
         sort = "score"
     order = order.get(sort)
     
     tick = Updates.midnight_tick()
     
     Q = session.query(Planet, PlanetHistory, Intel.nick, Alliance.name)
     Q = Q.outerjoin(Planet.intel)
     Q = Q.outerjoin(Intel.alliance)
     Q = Q.outerjoin((PlanetHistory, and_(Planet.id == PlanetHistory.id, PlanetHistory.tick == tick)))
     Q = Q.filter(Planet.active == True)
     
     if race.lower() in PA.options("races"):
         Q = Q.filter(Planet.race.ilike(race))
     else:
         race = "all"
     
     count = Q.count()
     pages = count/50 + int(count%50 > 0)
     pages = range(1, 1+pages)
     
     for o in order:
         Q = Q.order_by(o)
     Q = Q.limit(50).offset(offset)
     return render("planets.tpl", request, planets=Q.all(), offset=offset, pages=pages, page=page, sort=sort, race=race)
开发者ID:munin,项目名称:merlin,代码行数:34,代码来源:planets.py

示例8: execute

 def execute(self, request, user, sort=None):
     
     levels = [] + User.levels
     
     if sort is not None:
         levels = [("All member", levels[-1][1],),]
     
     order =  {"name"  : (asc(User.name),),
               "sponsor" : (asc(User.sponsor),),
               "access" : (desc(User.access),desc(User.carebears),asc(User.name),),
               "carebears" : (desc(User.carebears),),
               "planet" : (asc(Planet.x),asc(Planet.y),asc(Planet.z),),
               "defage" : (asc(User.fleetupdated),),
               }
     if sort not in order.keys():
         sort = "name"
     order = order.get(sort)
     
     members = []
     for level in levels:
         Q = session.query(User.name, User.alias, User.sponsor, User.access, User.carebears, Planet, User.fleetupdated,
                           User.phone, User.pubphone, User.id.in_(session.query(PhoneFriend.user_id).filter_by(friend=user)))
         Q = Q.outerjoin(User.planet)
         Q = Q.filter(User.active == True)
         Q = Q.filter(User.access >= level[1])
         Q = Q.filter(User.access < levels[levels.index(level)-1][1]) if levels.index(level) > 0 else Q
         for o in order:
             Q = Q.order_by(o)
         
         members.append((level[0], Q.all(),))
     
     return render("members.tpl", request, accesslist=members, tick=Updates.current_tick()*-1)
开发者ID:munin,项目名称:merlin,代码行数:32,代码来源:members.py

示例9: list

 def list(self, message, user, params):
     Q = session.query(Request)
     Q = Q.filter(Request.tick > Updates.current_tick() - 5)
     Q = Q.filter(Request.active == True)
     Q = Q.order_by(asc(Request.id))
     
     message.reply(" ".join(map(lambda request: "[%s: %s %s:%s:%s]" % (request.id, request.scantype, request.target.x, request.target.y, request.target.z,), Q.all())))
开发者ID:munin,项目名称:merlin,代码行数:7,代码来源:request.py

示例10: new

    def new(self, message, user, params):
        tick = Updates.current_tick()
        comment = params.group(3) or ""
        when = int(params.group(1))
        if when < PA.getint("numbers", "protection"):
            eta = when
            when += tick
        elif when <= tick:
            message.alert(
                "Can not create attacks in the past. You wanted tick %s, but current tick is %s." % (when, tick)
            )
            return
        else:
            eta = when - tick
        if when > 32767:
            when = 32767

        attack = Attack(landtick=when, comment=comment)
        session.add(attack)

        for coord in re.findall(loadable.coord, params.group(2)):
            if not coord[4]:
                galaxy = Galaxy.load(coord[0], coord[2])
                if galaxy:
                    attack.addGalaxy(galaxy)

            else:
                planet = Planet.load(coord[0], coord[2], coord[4])
                if planet:
                    attack.addPlanet(planet)

        session.commit()
        message.reply(str(attack))
开发者ID:ellonweb,项目名称:merlin,代码行数:33,代码来源:attack.py

示例11: execute

 def execute(self, request, user, id, x, y, z, when):
     planet = Planet.load(x,y,z)
     if planet is None:
         return self.attack(request, user, id, "No planet with coords %s:%s:%s" %(x,y,z,))
     
     tick = Updates.current_tick()
     when = int(when)
     if when < PA.getint("numbers", "protection"):
         eta = when
         when += tick
     elif when <= tick:
         return self.attack(request, user, id, "Can not book targets in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
     else:
         eta = when - tick
     if when > 32767:
         when = 32767        
     
     if planet.intel and planet.alliance and planet.alliance.name == Config.get("Alliance","name"):
         return self.attack(request, user, id, "%s:%s:%s is %s in %s. Quick, launch before they notice!" % (x,y,z, planet.intel.nick or 'someone', Config.get("Alliance","name"),))
     
     try:
         planet.bookings.append(Target(user=user, tick=when))
         session.commit()
     except IntegrityError:
         session.rollback()
         target = planet.bookings.filter(Target.tick == when).first()
         if target is not None:
             return self.attack(request, user, id, "Target %s:%s:%s is already booked for landing tick %s by user %s" % (x,y,z, when, target.user.name,))
     else:
         return self.attack(request, user, id, "Booked landing on %s:%s:%s tick %s (eta %s) for user %s" % (x,y,z, when, (when-tick), user.name,))
     
     return self.attack(request, user, id)
开发者ID:Hardware-Hacks,项目名称:merlin,代码行数:32,代码来源:book.py

示例12: execute

 def execute(self, request, user, page="1", sort="score"):
     page = int(page)
     offset = (page - 1)*50
     order =  {"score" : (asc(Alliance.score_rank),),
               "size"  : (asc(Alliance.size_rank),),
               "avg_score" : (asc(Alliance.score_avg_rank),),
               "avg_size"  : (asc(Alliance.size_avg_rank),),
               "members"   : (asc(Alliance.members_rank),),
               } 
     if sort not in order.keys():
         sort = "score"
     order = order.get(sort)
     
     tick = Updates.midnight_tick()
     
     Q = session.query(Alliance, AllianceHistory)
     Q = Q.outerjoin((AllianceHistory, and_(Alliance.id == AllianceHistory.id, AllianceHistory.tick == tick)))
     Q = Q.filter(Alliance.active == True)
     
     count = Q.count()
     pages = count/50 + int(count%50 > 0)
     pages = range(1, 1+pages)
     
     for o in order:
         Q = Q.order_by(o)
     Q = Q.limit(50).offset(offset)
     return render("alliances.tpl", request, alliances=Q.all(), offset=offset, pages=pages, page=page, sort=sort)
开发者ID:munin,项目名称:merlin,代码行数:27,代码来源:alliances.py

示例13: links

 def links(self, message, user, params):
     Q = session.query(Request)
     Q = Q.filter(Request.tick > Updates.current_tick() - 5)
     Q = Q.filter(Request.active == True)
     Q = Q.order_by(asc(Request.id))
     
     message.reply(" ".join(map(lambda request: "[%s: %s]" % (request.id, request.link,), Q[:5])))
开发者ID:munin,项目名称:merlin,代码行数:7,代码来源:request.py

示例14: execute

    def execute(self, message, user, params):
        
        fleetcount = int(params.group(1))
        comment = params.group(2)
        reply = ""

        if user.planet:
            scan = user.planet.scan("A")
            if scan is None:
                message.reply("Advanced Unit Scan not found for %s:%s:%s" % (user.planet.x, user.planet.y, user.planet.z))
                return
        else:
            message.reply("Planet not set. Use !pref planet=x:y:z")
            return

        scanage = Updates.current_tick() - scan.tick
        if scanage > 12:
            reply += "Warning: Scan is %d ticks old.\n" % scanage

        self.update_comment_and_fleetcount(user, fleetcount, comment)
        user.fleets.delete()
        for uscan in scan.units:
            user.fleets.append(UserFleet(ship_id=uscan.ship_id, ship_count=uscan.amount))
        session.commit()

        ships = user.fleets.all()
        
        reply += "Updated your def info to: fleetcount %s, updated: pt%s ships: " % (user.fleetcount, user. fleetupdated)
        reply += ", ".join(map(lambda x:"%s %s" % (self.num2short(x.ship_count), x.ship.name), ships))
        reply += " and comment: %s" %(user.fleetcomment)
        message.reply(reply)
开发者ID:JDD,项目名称:merlin,代码行数:31,代码来源:aumydef.py

示例15: execute

 def execute(self, message, user, params):
     
     search=params.group(1)
     
     Q = session.query(FleetLog)
     
     if search != "":
         ship = Ship.load(name=search)
         if ship is not None:
             Q = Q.filter(FleetLog.ship == ship)
         else:
             u = User.load(search, exact=False, access="member")
             if u is not None:
                 Q = Q.filter(FleetLog.user == u)
             else:
                 Q = Q.filter(FleetLog.id == -1)
     Q = Q.order_by(desc(FleetLog.tick))
     
     result = Q[:10]
     
     if len(result) < 1:
         message.reply("No matches found in the deflog for search '%s'"%(search,))
         return
     
     tick = Updates.current_tick()
     reply = ", ".join(map(lambda x:"%s gave %s %s to %s (%s)"%(x.user.name,self.num2short(x.ship_count),x.ship.name,x.taker.name,x.tick-tick),result))
     message.reply(reply)
开发者ID:Go3Media,项目名称:merlin,代码行数:27,代码来源:logdef.py


注:本文中的Core.maps.Updates类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。