Пример #1
0
def pages():
    """Generate all ranking pages and the HTML index."""
    def get_str(chart):
        return chart["str"].upper()

    def mk_cap(mode):
        return mode.capitalize()

    idx = index.read()
    for name in set(key for mode in (game.mode.star, game.mode.pop) for key in idx[mode]):
        tabs = []
        clean_name = clean(name)
        if exists(path.db.star + clean_name + ".json"): tabs.append(mk_cap(game.mode.star))
        if exists(path.db.nm + clean_name + ".json"): tabs.append(get_str(game.chart.nm))
        if exists(path.db.hd + clean_name + ".json"): tabs.append(get_str(game.chart.hd))
        if exists(path.db.mx + clean_name + ".json"): tabs.append(get_str(game.chart.mx))
        if exists(path.db.ex + clean_name + ".json"): tabs.append(get_str(game.chart.ex))
        if len(tabs) > 0:
            _page(tabs, name, "./images/disc")
    for name in (key for key in idx[game.mode.club]):
        if exists(path.db.club + clean(name) + ".json"):
            _page([mk_cap(game.mode.club)], name, "./images/club")
    for name in (key for key in idx[game.mode.mission]):
        if exists(path.db.mission + clean(name) + ".json"):
            _page([mk_cap(game.mode.mission)], name, "./images/mission")
    _page([mk_cap(game.mode.star), get_str(game.chart.nm), get_str(game.chart.hd), get_str(game.chart.mx), mk_cap(game.mode.pop), mk_cap(game.mode.club), mk_cap(game.mode.mission)], "Master")
    _index(idx)
Пример #2
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"]]
Пример #3
0
def main():
    return json.dumps({ 'info': 'product offers API' })

@app.route('/products')
def products():
    offer = lambda doc: {
                'id': doc['id'],
                'discountPct': random.randint(1, 80)
            }
    return json.dumps([offer(doc) for doc
                       in random.sample(app.docs, 64)])

@app.route('/manufacturers')
def manufacturer():
  manufacturers = set(doc['manufacturer'] for doc in app.docs
                      if 'manufacturer' in doc)
  deal = lambda m: {
             'manufacturer': m,
             'discountPct': random.randint(1, 10) * 5
         }
  return json.dumps([deal(m) for m
                     in random.sample(manufacturers, 3)])

if __name__ == "__main__":
  if len(sys.argv) < 2:
    print("Usage: {0} <csv file>".format(sys.argv[0]))
    sys.exit(1)

  app.docs = list(read(sys.argv[1]))
  app.run(port=8000, debug=True)
Пример #4
0
 def oldest_first(mode):
     idx = index.read()
     return sorted(idx[mode], key=lambda x: idx[mode][x]["timestamp"])