Example #1
0
def get(mode, name, chart=game.chart.nm):
    """The complete ranking of the specified mode and name.

    Arguments:
    mode -- One of the four game modes.
    name -- The full name of a disc, disc set, or mission.
    chart -- One of the four game charts.  Only relevant for Pop mode.

    """
    if mode == game.mode.star: address = url.ranking.star
    elif mode == game.mode.pop: address = url.ranking.pop
    elif mode == game.mode.club: address = url.ranking.club
    elif mode == game.mode.mission: address = url.ranking.mission
    else: raise ValueError("Invalid game mode")
    identifier = _id(mode, name)
    results = []
    for page in itertools.count(1):
        addr = address.format(identifier, page)
        if mode == game.mode.pop:
            addr += "&pt={}".format(chart["int"])
        records = urlopen_json(addr, "Ranking retrieval")
        results.extend([dict(zip(("rank", "djicon", "djname", "score"), (r["RANK"], r["DJICON"], r["DJNAME"], r["SCORE"]))) for r in records])
        if len(records) < 20:
            break
    return results
Example #2
0
def disc():
    """Download disc, disc set, and mission icons from the DJMAX site.

    An icon will be skipped if it is determined that it already exists.
    Existence is checked by a simple path check.

    """
    all_id_urls = (url.id.star, url.id.pop, url.id.club, url.id.mission)
    all_img_urls = (url.img.star, url.img.pop, url.img.club, url.img.mission)
    all_img_dirs = (path.img.star, path.img.pop, path.img.club, path.img.mission)
    all_keys = (site.key.star, site.key.pop, site.key.club, site.key.mission)
    all_pages = (site.pages.star, site.pages.pop, site.pages.club, site.pages.mission)
    all_suffixes = (1, 4, 1, 1)  # image suffix ranges

    for id_url, img_url, img_dir, key, end, suffix in zip(
        all_id_urls, all_img_urls, all_img_dirs, all_keys, all_pages, all_suffixes
    ):
        images = []
        for page in range(1, end + 1):
            for record in urlopen_json(id_url.format(page), "Retrieving image name"):
                images.append(
                    (record[key["image"]] + (".png" if key == site.key.mission else ""), clean(record[key["name"]]))
                )
        for image in images:
            unclean_name = image[0]
            name, ext = image[0].rsplit(".", 1)
            for i in range(1, suffix + 1):
                clean_name = "{}_{}.{}".format(image[1], i, ext)
                if exists(img_dir + clean_name):
                    continue
                if key == site.key.pop:
                    unclean_name = "{}{}.{}".format(name[:-1], i, ext)
                with open(img_dir + clean_name, "wb") as f:
                    f.write(urlopen_image(img_url.format(unclean_name)))
                print('Wrote: "{}{}"'.format(img_dir, clean_name))
Example #3
0
def _id(mode, name):
    """The identifier for a given mode and name."""
    if mode == game.mode.star: address, key = url.id.star, site.key.star
    elif mode == game.mode.pop: address, key = url.id.pop, site.key.pop
    elif mode == game.mode.club: address, key = url.id.club, site.key.club
    elif mode == game.mode.mission: address, key = url.id.mission, site.key.mission
    else: raise ValueError("Invalid game mode")
    page = index.read()[mode][name]["page"]
    for record in urlopen_json(address.format(page), "ID retrieval"):
        if record[key["name"]] == name:
            return record[key["id"]]
Example #4
0
def create():
    """Create the index."""
    all_modes = (game.mode.star, game.mode.pop, game.mode.club, game.mode.mission)
    all_ids   = (url.id.star, url.id.pop, url.id.club, url.id.mission)
    all_pages = (site.pages.star, site.pages.pop, site.pages.club, site.pages.mission)
    all_keys  = (key["name"] for key in (site.key.star, site.key.pop, site.key.club, site.key.mission))

    index = dict()
    for mode, address, end, key in zip(all_modes, all_ids, all_pages, all_keys):
        index[mode] = dict()
        for page in range(1, end + 1):
            for record in urlopen_json(address.format(page), "Create index"):
                index[mode][record[key]] = dict(zip(("timestamp", "page"), (0, page)))
    with open(path.index.db, "wb") as f:
        f.write(json.dumps(index, indent=1).encode())