Skip to content

njam/tinycards-python-api

 
 

Repository files navigation

Tinycards Python API

Build Status Coverage Status Codacy Badge Python Versions PyPI Version PyPI Status License: MIT

An unofficial Python API for Tinycards by Duolingo.

Installation

Install from PyPI

The easiest way to get started is to simple install the library like so:

$ pip install tinycards

Install from source

If you want to modify the library's source code and try out your changes locally, you might want to consider building from source which works like follows:

  1. Make sure Python with Setuptools is installed.
  2. From the project's root folder, install using pip:
$ pip install -e .

Run Tests

  1. In order to run the tests, you need to set the enviroment variables TINYCARDS_IDENTIFIER and TINYCARDS_PASSWORD.
  2. Then, from the project's root directory, simply start the pytest test runner:
$ pytest 
  1. When all tests were successful, pytest will exit with 0.

Usage

Below is a list of some of the most common functions. For a more practical example, see the csv_to_deck.py script.

Initialise a new client

>>> # A new client with the given identification (e.g., mail address) and password.
>>> client  = tinycards.Tinycards('identification', 'password')
'Logged in as 'username' ([email protected])'
>>> # If no identification or password are specified, they are taken from ENV.
>>> client  = tinycards.Tinycards()
'Logged in as 'username' ([email protected])'

Get info about the currently logged in user.

>>> user = client.get_user_info()
{
  username: 'bachman',
  email: '[email protected]',
  fullname: 'Erlich Bachman',
  ...
}

Get all decks of a user

>>> all_decks = client.get_decks()
>>> [deck.title for deck in all_decks]
['Deck 1', 'Deck 2', 'Deck 3']

Update an existing deck

>>> deck_1 = client.find_deck_by_title('Deck 1')
>>> deck_1.title = 'Deck 1.1'
>>> client.update_deck(deck_1)
{
  'title': 'Deck 1.1',
  ...
}

Delete an existing deck

>>> deck = client.find_deck_by_title('Some Deck')
{
  'title': 'Some Deck',
  'id': '8176b324-addc-495d-aadc-fad005e5b439'
  ...
}
>>> client.delete_deck(deck.id)
{
  'title': 'Some Deck',
  'id': '8176b324-addc-495d-aadc-fad005e5b439'
  ...
}
>>> deck = client.find_deck_by_title('Some Deck')
None

Release a new Version

  1. Bump the version in setup.py.
  2. Push a new tag to GitHub.
  3. The Travis build will deploy the release to PyPI.

About

An unofficial Python API for Tinycards by Duolingo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%