Code Monkey home page Code Monkey logo

python-kanka's Introduction

python-kanka

This is a python interface to the API from https://kanka.io. It's still early development so use it at your own risk.

Installation

This module is compatible with Python >= 3.7. When inside the repository root, install the module with

pip install -r requirements.txt
python setup.py install

A virtual environment is recommended.

Usage

To get started you need an API token, see https://kanka.io/en-US/docs/1.0/setup (oAuth is not supported by this module).

Create the client with

import kanka
token = {your_api_token_string}
client = kanka.KankaClient(token)

With this you can get a list of campaigns and import a campaign by its ID:

client.get_campaigns()
my_campaign = client.campaign({campaign_id})

With the campaign object you have access to its entities. Get a list of entities wih Campaign.get_list_of({entities}) or import an entity with the matching method.

my_campaign.get_list_of("characters")
my_campaign.get_list_of("journals")

char = my_campaign.character({character_id)
char.age
last_session = my_campaign.journal({session_id})
last_session.name

Searching for entities

You can search for entities using the /search endpoint of the kanka API:

match = my_campaign.search("Legolas")

This returns a list of entity objects with names matching the search term. If for example the term "Legolas" matches twos characters and one location, the variable match will contain two StoredCharacter objects and one StoredLocation object as a list. You can access the entity's attributes as shown above with

match[0].name    # match[0] is the first list entry,
                 # a StoredCharacter object
match[2].map_url # match[2] is the third list entry,
                 # a StoredLocation object

Create new entity

You can create a new (empty) entity with for example

gimli = my_campaign.new_entity("character")
vulcan = my_campaign.new_entity("race")

All attributes will be set to None except the entity name, which is set to "New {entity}". You can fill out as many attributes as you like and then upload the entity with

gimli.upload()

You'll receive a json dictionary with the data of the newly created entity if successfull.

Delete an entity

Delete an entity of a campaign using the campaigns delete method by specifying the entity type and the entity id, for example:

my_campaign.delete("character", 666666)

If successfull, the method returns True.

Download campaign data

You can also import all the entities of a campaign into a StoredCampaign object:

my_campaign = client.import_campaign({campaign_id})
my_campaign.characters         # displays a list of all characters
my_campaign.characters[3].name # displays the name of the fourth character in the list

At the moment not all entities are implemented, see table below.

Entity name retrieve create update delete
Profile ✔️
Campaign ✔️
Character ✔️ ✔️ ✔️ ✔️
Location ✔️ ✔️ ✔️ ✔️
Family ✔️ ✖️ ✖️ ✖️
Organisation ✔️ ✔️ ✔️ ✔️
Item ✖️ ✖️ ✖️ ✖️
Note ✔️ ✔️ ✔️ ✔️
Event ✖️ ✖️ ✖️ ✖️
Calendar ✖️ ✖️ ✖️ ✖️
Race ✔️ ✔️ ✔️ ✔️
Quest ✔️ ✔️ ✔️ ✔️
Journal ✔️ ✔️ ✔️ ✔️
Ability ✖️ ✖️ ✖️ ✖️
Tag ✖️ ✖️ ✖️ ✖️
Conversation ✖️ ✖️ ✖️ ✖️
Dice Roll ✖️ ✖️ ✖️ ✖️

python-kanka's People

Contributors

rbtnx avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ayanb73

python-kanka's Issues

Update Traits Class

Traits seem to have changed, there is no is_private property which leads to errors when importing Characters with traits, invoking MissingValueError: missing value for field "traits.is_private"

Also check for possible additional changes.

"header_full" and "has_custom_header" keys

"_possible_keys" should include the "header_full" and "has_custom_header" keys. This is true for the Journal and Character types. Otherwise loading an entity will not work. Adding the keys fixes the issue.

I don't know if non-paid campaigns will show this error.

Update entities

There doesn't seem to be a way to update entities. the upload() method doesn't work for this purpose. The readme says that updating is implemented for characters, but I'm not sure how to do it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.