Beispiel #1
0
 def extract(directory):
     names = dict()
     for record in ls(directory):
         with open(directory + record, "rb") as f:
             disc = json.loads(f.read().decode())
         all_dj.update((dj["djname"], dj["djicon"]) for dj in disc["ranking"])
         names[disc["name"]] = (9999, 0)  # default rank and score
     return names
Beispiel #2
0
def icon():
    """Download DJ icons from the DJMAX site.

    Scans the local database and downloads the necessary DJ icons.  An icon will
    be skipped if it is determined that it already exists.  Existence is checked
    by a simple path check.

    """
    icons = set()
    for db in (path.db.star, path.db.nm, path.db.hd, path.db.mx, path.db.ex, path.db.club, path.db.mission):
        for record in ls(db):
            with open(db + record, "rb") as f:
                data = json.loads(f.read().decode())
            icons.update([dj["djicon"] for dj in data["ranking"]])
    for icon in icons:
        if exists(path.img.icon + icon):
            continue
        with open(path.img.icon + icon, "wb") as f:
            f.write(urlopen_image(url.img.icon.format(icon)))
        print('Wrote: "{}{}"'.format(path.img.icon, icon))
Beispiel #3
0
def master():
    """Use the local DJ database to create the master score records."""
    pop_master = {}

    for mode in (game.mode.star, game.chart.nm["str"], game.chart.hd["str"], game.chart.mx["str"], game.chart.ex["str"], game.mode.club, game.mode.mission):
        master = []
        for record in ls(path.db.dj):
            with open(path.db.dj + record, "rb") as f:
                record = json.loads(f.read().decode())
            master_score = sum([v[1] for k, v in record[mode].items()])
            if master_score:
                master.append((record["icon"], record["name"], master_score))
            if mode in (game.chart.nm["str"], game.chart.hd["str"], game.chart.mx["str"], game.chart.ex["str"]):
                if record["name"] not in pop_master:
                    pop_master[record["name"]] = [record["icon"], record["name"], master_score]
                else:
                    pop_master[record["name"]][2] += master_score
        master = [dict(zip(("rank", "djicon", "djname", "score"), (rank + 1, dj[0], dj[1], dj[2]))) for rank, dj in enumerate(sorted(master, key=lambda x: x[2], reverse=True))]
        with open("{}{}.json".format(path.db.master, mode), "wb") as f:
            f.write(json.dumps({"ranking": master}, indent=1).encode())

    pop_master = [dict(zip(("rank", "djicon", "djname", "score"), (rank + 1, dj[0], dj[1], dj[2]))) for rank, dj in enumerate(sorted(pop_master.values(), key=lambda x: x[2], reverse=True))]
    with open("{}{}.json".format(path.db.master, "pop"), "wb") as f:
        f.write(json.dumps({"ranking": pop_master}, indent=1).encode())
Beispiel #4
0
 def fill(mode, directory):
     for record in ls(directory):
         with open(directory + record, "rb") as f:
             disc = json.loads(f.read().decode())
         for dj in disc["ranking"]:
             all_dj[dj["djname"]][mode][disc["name"]] = (dj["rank"], dj["score"])