示例#1
0
 def setup_content_doc(pageContext, title):
     doc = pageContext.htmldoc
     doc.start_head()
     doc.add_tag("title", title, inline=False)
     doc.add_tag("link", attrs=dict(rel="stylesheet", type="text/css", href="/tibstats.css"), inline=False)
     doc.add_tag("link", attrs=dict(rel="icon", type="image/gif", href="http://static.tibia.com/images/gameguides/skull_black.gif"), inline=False)
     doc.start_body()
     with doc.open_tag("div", {"id": "menu"}):
         for p in PAGES.values():
             try:
                 title = p.baseTitle
             except AttributeError:
                 continue
             path = p.basePath
             world = pageContext.get_selected_world()
             if world:
                 path += "?" + urllib.urlencode({"world": world})
             doc.add_tag("a", title, attrs={"href": path})
             doc.add_tag("br")
         with doc.open_tag("form", attrs={"method": "get"}):
             doc.add_tag("input", attrs=dict(type="submit", value="Set world"))
             with doc.open_tag("select", attrs={"size": 1, "name": "world"}):
                 def add_selected_world(world, attrs):
                     if pageContext.get_selected_world() == world:
                         attrs["selected"] = None
                     return attrs
                 doc.add_tag("option", "ALL WORLDS", attrs=add_selected_world(None, {"value": ""}))
                 for world in sorted(a["name"] for a in dbiface.get_worlds()):
                     doc.add_tag("option", world, attrs=add_selected_world(world, {"value": world}))
     doc.open_tag("div", {"id": "content"}, inline=False)
     return doc
示例#2
0
    def setup_content_doc(pageContext, title):
        doc = pageContext.htmldoc
        doc.start_head()
        doc.add_tag("title", title, inline=False)
        doc.add_tag("link",
                    attrs=dict(rel="stylesheet",
                               type="text/css",
                               href="/tibstats.css"),
                    inline=False)
        doc.add_tag(
            "link",
            attrs=dict(
                rel="icon",
                type="image/gif",
                href="http://static.tibia.com/images/gameguides/skull_black.gif"
            ),
            inline=False)
        doc.start_body()
        with doc.open_tag("div", {"id": "menu"}):
            for p in PAGES.values():
                try:
                    title = p.baseTitle
                except AttributeError:
                    continue
                path = p.basePath
                world = pageContext.get_selected_world()
                if world:
                    path += "?" + urllib.urlencode({"world": world})
                doc.add_tag("a", title, attrs={"href": path})
                doc.add_tag("br")
            with doc.open_tag("form", attrs={"method": "get"}):
                doc.add_tag("input",
                            attrs=dict(type="submit", value="Set world"))
                with doc.open_tag("select", attrs={
                        "size": 1,
                        "name": "world"
                }):

                    def add_selected_world(world, attrs):
                        if pageContext.get_selected_world() == world:
                            attrs["selected"] = None
                        return attrs

                    doc.add_tag("option",
                                "ALL WORLDS",
                                attrs=add_selected_world(None, {"value": ""}))
                    for world in sorted(a["name"]
                                        for a in dbiface.get_worlds()):
                        doc.add_tag("option",
                                    world,
                                    attrs=add_selected_world(
                                        world, {"value": world}))
        doc.open_tag("div", {"id": "content"}, inline=False)
        return doc
示例#3
0
def world_select(htmldoc, curworld, onchange):
    selectAttrs = {"size": 1, "name": "world"}
    if onchange:
        selectAttrs["onchange"] = "this.form.submit();"
    with htmldoc.open_tag(
            "select",
            selectAttrs,
            inline=False):
        def add_selected_world(world, attrs):
            if curworld == world:
                attrs["selected"] = None
            return attrs
        htmldoc.newline()
        htmldoc.add_tag("option", "All Worlds", attrs=add_selected_world(None, {"value": ""}))
        for world in sorted(a["name"] for a in dbiface.get_worlds()):
            htmldoc.newline()
            htmldoc.add_tag("option", world, attrs=add_selected_world(world, {"value": world}))
示例#4
0
def world_select(htmldoc, curworld, onchange):
    selectAttrs = {"size": 1, "name": "world"}
    if onchange:
        selectAttrs["onchange"] = "this.form.submit();"
    with htmldoc.open_tag("select", selectAttrs, inline=False):

        def add_selected_world(world, attrs):
            if curworld == world:
                attrs["selected"] = None
            return attrs

        htmldoc.newline()
        htmldoc.add_tag("option",
                        "All Worlds",
                        attrs=add_selected_world(None, {"value": ""}))
        for world in sorted(a["name"] for a in dbiface.get_worlds()):
            htmldoc.newline()
            htmldoc.add_tag("option",
                            world,
                            attrs=add_selected_world(world, {"value": world}))
示例#5
0
def continuous_update(*worlds):

    worlds = set(worlds)

    def get_option(optstr):
        try:
            worlds.remove(optstr)
            return True
        except KeyError:
            return False

    immediate = get_option("immediate")
    once = get_option("once")
    if not worlds:
        worlds = set((x["name"] for x in dbiface.get_worlds()))

    jobqueue = Queue.Queue()
    threads = []
    errflag = threading.Event()
    for a in xrange(5):
        threads.append(
            threading.Thread(target=_continuous_update_thread_func,
                             args=(jobqueue, errflag)))
        threads[-1].start()

    try:
        nextUpdate = next_tibiacom_whoisonline_update()
        while True:
            if not immediate:
                logging.info("Waiting for %s",
                             time.asctime(time.localtime(nextUpdate)))
                while True:
                    if time.time() >= nextUpdate:
                        break
                    else:
                        time.sleep(int(time.time()) + 1 - time.time())
                nextUpdate = next_tibiacom_whoisonline_update()

            startTime = int(time.time())

            # update the world online lists
            for w in worlds:
                jobqueue.put((TibstatDatabase.update_world_online, w))
            jobqueue.join()
            if errflag.is_set():
                return

            # check the time hasn't gone over into the next update period
            if not immediate:
                assert time.time() < nextUpdate

            charCount = 0
            for w in worlds:
                for row in TibstatDatabase().get_online_chars(
                        after=(nextUpdate - 10 * 60), world=w):
                    jobqueue.put((TibstatDatabase.update_char, row["name"]))
                    charCount += 1
            logging.info("Updating %d chars", charCount)
            jobqueue.join()
            if errflag.is_set():
                return

            logging.info("Update took %ds", int(time.time()) - startTime)
            if once:
                break
            immediate = False
    finally:
        assert jobqueue.empty()
        for a in threads:
            jobqueue.put(None)
        for a in threads:
            a.join()
示例#6
0
def continuous_update(*worlds):

    worlds = set(worlds)
    def get_option(optstr):
        try:
            worlds.remove(optstr)
            return True
        except KeyError:
            return False
    immediate = get_option("immediate")
    once = get_option("once")
    if not worlds:
        worlds = set((x["name"] for x in dbiface.get_worlds()))

    jobqueue = Queue.Queue()
    threads = []
    errflag = threading.Event()
    for a in xrange(5):
        threads.append(threading.Thread(
                target=_continuous_update_thread_func,
                args=(jobqueue, errflag)))
        threads[-1].start()

    try:
        nextUpdate = next_tibiacom_whoisonline_update()
        while True:
            if not immediate:
                logging.info("Waiting for %s", time.asctime(time.localtime(nextUpdate)))
                while True:
                    if time.time() >= nextUpdate:
                        break
                    else:
                        time.sleep(int(time.time()) + 1 - time.time())
                nextUpdate = next_tibiacom_whoisonline_update()

            startTime = int(time.time())

            # update the world online lists
            for w in worlds:
                jobqueue.put((TibstatDatabase.update_world_online, w))
            jobqueue.join()
            if errflag.is_set():
                return

            # check the time hasn't gone over into the next update period
            if not immediate:
                assert time.time() < nextUpdate

            charCount = 0
            for w in worlds:
                for row in TibstatDatabase().get_online_chars(
                        after=(nextUpdate - 10 * 60),
                        world=w):
                    jobqueue.put((TibstatDatabase.update_char, row["name"]))
                    charCount += 1
            logging.info("Updating %d chars", charCount)
            jobqueue.join()
            if errflag.is_set():
                return

            logging.info("Update took %ds", int(time.time()) - startTime)
            if once:
                break
            immediate = False
    finally:
        assert jobqueue.empty()
        for a in threads:
            jobqueue.put(None)
        for a in threads:
            a.join()