Classes

Curation

class fpclib.Curation(curation=None, **kwargs)

This is the base class for every kind of curation. If you want a good tutorial on how to use this class, see The Basics. Extend this class to redefine it’s methods. Constructor:

Accepts a single Curation object as an argument or arguments in the same format as Curation.set_meta(). The new curation will first have it’s metadata, logo, screenshot, added args, and id deep-copied from curation’s first if it’s available, then have that data modified with kwargs if available. This curation object will be linked to that curation object.

Raises:

TypeError – If curation is not an instance of Curation.

Attributes

RESERVED_APPS

Curation.RESERVED_APPS = {'extras', 'message'}

A set containing all of the reserved headings that cannot be used in additional applications. The check is case-insensitive, hence they are lowercase.

ARGS

Curation.ARGS

A dictionary containing mappings for the arguments in Curation.set_meta() and Curation.get_meta() to the Curation.meta dictonary.

Here’s a table of what each argument maps to:

Meta Tag

Args

Title

title, name

Alternate Titles

alternateTitles, altTitles, alts

Library

library, lib

Series

series, ser

Developer

developer, dev

Publisher

publisher, pub

Play Mode

playMode, mode

Release Date

releaseDate, date

Version

version, ver

Languages

languages, lang

Extreme

extreme, nsfw

Tags

tags, genre

Source

source, src, url

Platform

platform, tech

Status

status, s

Application Path

applicationPath, appPath, app

Launch Command

launchCommand, launch, cmd

Game Notes

gameNotes, notes

Original Description

originalDescription, description, desc

Curation Notes

curationNotes, cnotes

You can find the description of each of these tags on the Curation Format page on the Flashpoint wiki.

Member Fields

meta

Curation.meta: dict

An ordered dictionary containing all metadata for the curation. While you can modify it directly, it is recommended that you use Curation.set_meta() and Curation.get_meta() instead.

args

Curation.args: dict

A dictionary containing all arguments passed in through Curation.set_meta() that do not map to any metadata. You can use this to pass in extra information that you want to use in Curation.parse() or other methods for custom classes.

ss

Curation.ss: str = None

A url pointing to an image to be used as the screenshot for this curation. Any non-PNG files will be converted into PNG files when downloaded. You can modify it at will.

id

Curation.id: str = str(uuid.uuid4())

A string UUID identifying this curation. By default this is the name of the folder the curation will be saved to when Curation.save() is called. You can re-generate an id by using Curation.new_id().

Methods

new_id()

Curation.new_id()

Generate a new uuid for this curation.

See:

Curation.id

set_meta()

Curation.set_meta(**kwargs)

Set the metadata with kwargs. This method does not do error checking.

Since 1.5:

You can also just set the metadata directly through the curation instead; e.g., curation.title = 'Title Goes Here'

Parameters:

kwargs (**) – A list of arguments to set the metadata with. To see what you can use for kwargs, see Curation.ARGS. Any value passed in that is not in Curation.ARGS will still be stored and can be retrieved through Curation.get_meta().

Note:

For example, to set the title of a curation you would use curation.set_meta(title='Title Goes Here')

get_meta()

Curation.get_meta(key)

Get the metadata/args referenced by key.

Since 1.5:

You can also just get the metadata directly through the curation instead; e.g., myVar = curation.title

Parameters:

key (str) – The name of an argument to get the value of. You can either use the keys referenced by Curation.ARGS or the name of the argument you passed in through Curation.set_meta().

Returns:

The meta referenced by key, the data associated with it, or None if it hasn’t been set.

add_app()

Curation.add_app(heading, launch, path='FPSoftware\\Flash\\flashplayer_32_sa.exe')

Add an additional application. To add extras or a message, use Curation.add_ext() and Curation.add_msg() respectively.

Parameters:
  • heading (str) – The name of the additional application.

  • launch (str) – The name of the launch command for the additional application.

  • path (str) – The application path for the additional application. Defaults to FLASH.

Seealso:

The Additional Applications section of the Curation Format page.

Note:

Trying to add an additional app with a heading that already exists will result in replacing it.

Raises:

ValueError – If heading is in Curation.RESERVED_APPS.

add_ext()

Curation.add_ext(folder)

Add extras from folder.

Parameters:

folder (str) – The name of the folder the extras are located in.

Seealso:

The Extras section of the Curation Format page.

Note:

Calling this method more than once will replace the current extras.

add_msg()

Curation.add_msg(message)

Add message.

Parameters:

message (str) – The message to add to this curation.

Seealso:

The Messages section of the Curation Format page.

Note:

Calling this method more than once will replace the current message.

del_app()

Curation.del_app(heading)

Delete an additional application, extras, or message.

Parameters:

heading (str) – The name of the additional application to delete. Use “Extras” or “Message” to delete an extras or message.

Raises:

KeyError – If the app doesn’t exist.

get_yaml()

Curation.get_yaml()

Use ruamel.yaml to parse Curation.meta into a string.

Returns:

A yaml string with the formatted metadata.

soupify()

Curation.soupify()

Get’s the relevant BeautifulSoup object of this curation to pass to Curation.parse().

This method’s sole purpose is to make it possible to overwrite the process for getting the soup object for a particular url. This is useful in case certain websites have special protection preventing you from downloading pages too fast.

Returns:

get_soup() with the source part of the metadata as it’s parameter.

parse()

Curation.parse(soup)

Parse for metadata with a soup object provided by Curation.soupify(). By default this method does nothing and must be overwritten to give it functionality.

See:

Curation.save().

get_files()

Curation.get_files()

Download/Create all necessary content files for this curation. By default this method downloads the file linked by all launch commands and creates all the directories necessary for them to be in. It will not raise any errors if downloading fails.

See:

Curation.save().

save_image()

Curation.save_image(url, file_name)

Download the image from url and save it to file_name as a PNG file; this method is primarily used for downloading logos and screenshots. It may be overwriten to add custom image-downloading abilities, but by default it just calls the download_image() function.

Parameters:
  • url (str) – The url location of the image to download.

  • file_name (str) – The location/name of the file to save to.

See:

Curation.save().

save()

Curation.save(use_title=False, overwrite=False, parse=False, validate=0, save_items=15)

Save the curation to a folder with the name of Curation.id. Consecutive calls to this method will not overwrite the previous folder, but will instead save it as “Curation (2)”, “Curation (3)”, etc.

Parameters:
  • use_title (str) – If True, the folder will be generated with the title of the curation instead of its id.

  • overwrite (bool) – If True, this method will mix and overwrite files in existing curation folders instead of making the folder “Curation (2)”, “Curation (3)”, etc.

  • parse (bool) – Added in 1.3: If True, this function will call Curation.parse() before saving metadata.

  • validate (int) – Added in 1.3: Mode to validate this curation’s metadata with. 0 (default) means do not validate, 1 means flexibly validate, and 2 means rigidly validate.

  • save_items (int) – Flags determining what items to save as part of this curation. By default this is EVERYTHING. If you wanted to save only the meta and logo, for example, use save_items=META|LOGO.

Raises:

InvalidMetadataErrorAdded in 1.3: If this curation has invalid metadata and validate is set to 1 or higher.

See:

EVERYTHING and the surrounding constants, along with get_errors()

The process of this method is as follows:

  1. Create a BeautifulSoup object with Curation.soupify().

  2. Call method Curation.parse() with the soup object just created.

  3. New in 1.3: Validate this curation’s metadata with Curation.get_errors() if validate is 1 or higher. Raise an error if it’s incorrect.

  4. Create curation folder for the curation and set it to the working directory (the working directory will be reset in the case of any error).

  5. Create meta file with Curation.get_yaml() and download logo and screenshot through Curation.save_image() if they are available.

  6. Create “content” folder and set it to the working directory.

  7. Call method Curation.get_files() to get all files necessary for the curation.

  8. Reset working directory.

You may overwrite any of these methods to allow for custom usability.

get_errors()

Curation.get_errors(rigid=False)

Validate this curation to see if it’s metadata is correct.

Parameters:

rigid (bool) – If True, this function will make sure this Curation’s metadata is in order with the Curation Format page. By default, this function checks everything except Tags, Platform, and Application Path. Note that rigid checking will call update() if it has not been called already or failed previously.

Seealso:

Curation.check_source()

Returns:

A list of problems with this curation as strings. If there are no errors with this curation, an empty list will be returned.

Since 1.3:

check_source()

Curation.check_source()

Validates this curation’s current source. Called by Curation.get_errors().

Returns:

A string of the source’s current problem or None if there is no problem.

Since 1.3:

TestCuration

class fpclib.TestCuration(curation=None, **kwargs)

An extension of Curation that curates interactive buddy.

BrokenCuration

class fpclib.BrokenCuration(curation=None, **kwargs)

An extension of Curation that has literally everything wrong with it when parsed.

Since 1.3:

DateParser

class fpclib.DateParser(format, year=None, month=None, day=None)

Initialize a regex-powered date parser that gets initialized with a specific format and can parse any date into the proper iso format. It does not check that the date is a real date. The constructor takes a string format specifying a regex to search for in future parsed strings. Note that the regex is case insensitive. Use these macros in the format string to specify parts of the date:

“<y>” for year number to match - replaced with the capture group “(?P<year>d{4})”, “<m>” for month to match - replaced with the capture group “(?P<month>d{1,3}|[A-Za-z]+)”, and “<d>” for day to match - replaced with the capture group “(?P<day>d{1,3})”

Month and day are optional, though using day requires using month. Note that the year, month, and day are automatically padded to the right number of zeros (4, 2, 2) automatically.

If the macros don’t quite work for you, feel free to use named capture groups and the callbacks “year”, “month”, and “day”, which are called on the respective matched parts of a parsed string to turn it into the right number format to use in the returned string. If the “month” callback is not set, it defaults to DateParser.get_month().

Parameters:
  • format (str) – A string containing a regex and macros specifying how to parse strings.

  • year (func) – A function to turn the matched “year” part of a parsed date into the right number format.

  • month (func) – A function to turn the matched “month” part of a parsed date into the right number format.

  • day (func) – A function to turn the matched “day” part of a parsed date into the right number format.

Raises:

ValueError – if the given format does not contain a “year” named group/macro or contains a “day” named group/macro without the “month” named group/macro.

Since 1.6:

Methods

parse()

DateParser.parse(s)

Uses this date format object to parse the given string s into a proper iso date.

Parameters:

s (str) – A string to parse for a date.

Returns:

An iso date parsed from string s

Raises:

ValueError – if no date in s could be found.