rogue_scores

rogue_scores is an online Rogue leaderboard as well as a script to upload local user scores to it. Once installed, you only have to run rogue_scores and the script will upload your scores for you.

The script will ask you which server to use the first time you’ll start it and remember this choice. You can override the remembered choice by setting the ROGUE_SCORES_SERVER environment variable, or delete ~/.rogue-scores-server to remove the script’s remembered choice.

Install

With pip:

[sudo] pip install rogue_scores

Guide

API Reference

rogue_scores.scores

This module is used to get and parse local user scores.

rogue_scores.scores.get_scores(command='rogue')[source]

Return a list of local user scores, as given by the command rogue -s. These scores should be ordered from the best score to the worst one, and limited to 10, but this limit is not enforced by the function.

Keyword arguments:
  • command (string, default: rogue): the command to use to run rogue.
rogue_scores.scores.parse_line(l)[source]

Parse a line from the scores given by Rogue and return a score as a tuple containing the user’s name, score, and result. If the line wasn’t correct, it returns None.

>>> parse_line(' 1   783 baptiste: killed on level 8 by a centaur.')
('baptiste', 783, 'killed on level 8 by a centaur.')

rogue_scores.upload

This module provides tools to upload Rogue scores to a remote server.

rogue_scores.upload.post_scores(scores, **kwargs)[source]

Post some scores to a remote server and return a boolean depending on the request’s success. These scores should be a list of tuples, as returned by rogue_scores.scores.get_scores. Optional keyword arguments are:

Keyword arguments:
  • protocol (string, default: http)
  • target (string, default: localhost:5000)

rogue_scores.cli

rogue_scores.cli.run()[source]

Run the command-line interface

rogue_scores.cli.set_server()[source]

Ask the user for a server address and store it in a local file.

rogue_scores.web

rogue_scores.web.app

This is a Web server for an online Rogue leaderboard. This is a Flask application with a couple helpers to parse POST’ed scores.

There’s currently no limit on the number of scores to store, and these are stored in a local JSON file. You can set the directory used for this file (by default it’s the current one) with ROGUE_SCORES_PATH.

rogue_scores.web.store

This modules provides functions to deal with scores stored on the Web server. Each score is represented as a dict-like object, with the following keys:

  • level
  • score
  • user: user’s name
  • cause: the monster’s name if the user was killed, the death cause if the user died of starvation or hypothermia
  • status (str): died, killed, quit

These keys can be None (or 0 for numerical ones) if the attribute is not set.

exception rogue_scores.web.store.BadScoreFormatException(s)[source]

This exception is raised when a wrongly formatted score is given to a ScoresStore instance’s add method.

class rogue_scores.web.store.Score(**kwargs)[source]

A score. This object implements some dict-like methods to provide an easy access to its attributes. It have at least these ones: level, score (default: 0), user, status, cause (default: None).

New in version 0.0.7.

class rogue_scores.web.store.ScoresStore(path=None, **kwargs)[source]

A scores store. This is based on a JSON file, but the interface should not depend on the underlying storage method.

>>> s = ScoresStore('/tmp/foo')
>>> s.add({'user': 'foo', 'level': 42, 'status': 'quit'})
1
>>> len(s)
1
>>> s.save()
None

New in version 0.0.7.

add(*scs, **kwargs)[source]

Add one or more scores to the store. These are sanitized before insertion, and missing informations are added via parsing if possible. It returns the number of inserted items. An item is not added if:

  • it’s already present
  • it doesn’t contain basic info on the score, like no user or a null score

Keyword arguments can be used to set default values on all added scores.

get(limit)[source]

Return at most limit scores

json(**kwargs)[source]

Return a JSON representation of this store

save()[source]

Save the current scores on disk, if the store’s path is not None.

rogue_scores.web.store.parse_text(text)[source]

Parse a score’s text and return a dictionnary of attributes: level, status, cause. Only a subset of these attributes might be returned if the text couldn’t be parsed or some of them aren’t relevant.

status can be either killed (by a monster), quit, died (e.g. of starvation) or won. This function should work with multiple text variants.

>>> parse_text("killed on level 12 by a quagga.")
{'level': 12, 'status': 'killed', 'cause': 'quagga'}
>>> parse_text("quit on level 3.")
{'level': 3, 'status': 'quit'}
>>> parse_text("died of hypothermia on level 6")
{'level': 6, 'status': 'died', 'cause': 'hypothermia'}
>>> parse_text("killed on level 3 by hypothermia.")
{'level': 3, 'status': 'died', 'cause': 'hypothermia'}

New in version 0.0.7.

rogue_scores.web.stats

This modules helps computing interesting stats about the scores stored on the Web server.

rogue_scores.web.stats.stats(scores)[source]

Compute stats on a ScoresStore, and return a dict that can then be used in a template. Each value is a string, and current keys are:

  • max_level: higher level, with the corresponding user
  • most_active: most games played by one user
  • best_killer: monster with the most kills

If multiple users or monsters match a criteria for one of these keys, only one of them will be picked.

Changes

v0.1.0 (upcoming version)

  • favicon added on the web page

v0.0.9 (03/06/2014)

All changes of this version are in the upload script.

  • support for ROGUE_SCORES_SERVER
  • --version flag support
  • redirections are now followed
  • User-Agent header added

v0.0.8 (31/05/2014)

This release fixes a problem in the previous version where the limit of 20 scores has been removed.

v0.0.7 (31/05/2014)

This is a breaking change on the server side API, but is fully compatible with previous upload script versions. Unless you have Python code relying on rogue_scores.web‘s functions, it’s ok to upgrade.

  • more log messages on the server side
  • stats added on the Web page
  • /scores now serves the JSON scores file, and /scores?pretty serves a pretty-printed version
  • rogue_scores.web moved to rogue_scores.web.app
  • scores-related functions moved from web to web.store, with Score and ScoresStore classes
  • scores are now internally stored as JSON objects instead of list
  • the Web page now shows each score’s level, status and cause.

v0.0.6 (27/05/2014)

  • ROGUE_SCORES_PATH support
  • the default Web scores file location is now the current directory

v0.0.5 (27/05/2014)

  • http[s] is not mandatory anymore when entering the remote server
  • help text added on the Web index page

v0.0.4 (26/05/2014)

  • local server name file parsing fixed

v0.0.3 (26/05/2014)

  • default Web scores file location moved to ~/.rogue-scores.json
  • logging added

v0.0.2 (26/05/2014)

  • dependencies list fixed

v0.0.1 (26/05/2014)

  • initial release