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.