Looks like the Great Firewall or something like it is preventing you from completely loading www.skritter.com because it is hosted on Google App Engine, which is periodically blocked. Try instead our mirror:

legacy.skritter.cn

This might also be caused by an internet filter, such as SafeEyes. If you have such a filter installed, try adding appspot.com to the list of allowed domains.

Vocab Endpoint

Vocabs store all the general and user-specific information about a given word. Use this endpoint if you would like to:

  • Search for a word, given a writing or reading/pinyin.
  • Gather up all of a user's starred words, mnemonics, banned words, or custom definitions.
  • Find all words that have a given character in them.
  • Get information for Items you have already collected.

If you're downloading a user's entire collection of Items, fetch the Items by themselves first, then fetch related Vocabs in batches through this URL. Otherwise, use the include_vocabs parameter while Item fetching.

GET http://legacy.skritter.com/api/v0/vocabs

Parameters

  • q
    searches the database for the given writing and/or reading. Uses the same search system as the list editor on the site, so it's pretty flexible. Suggested format: tab separated fields in the order: writing, reading, definition.
  • sort
    response sort order.
    "starred": when a word was starred
    "banned": when a word was banned or it's banned settings were changed
    "mnemonic": when a mnemonic was changed
    "customDefinition": when a custom definition was changed
    "all": when any of the above properties were changed
  • offset
    timestamp that filters the result based on sort type. For example, if sort is "starred", only returns Vocabs starred after the given offset.
  • cursor
    string used for pagination
  • lang
    The language of the Vocabs you want to search or query for.
    (default: user setting)
  • limit
    maximum number of Vocabs to fetch
    (default: 100) (max: 100)
  • ids
    pipe-separated list of Vocabs to fetch. Overrides any query or search based properties used.
  • fields comma-separated list of Vocab properties to return.
    (default: all)
  • definition_langs
    comma-separated list of languages the definitions should include. If 'all', then all definitions are returned.
    (default: English and user setting)
  • include_containing
    if there is only one single-character Vocab by query, returns a list of Vocabs that include the character.
    (default: false)
  • include_hidden
    include vocabs whose priority is less than 0
    (default: false)
  • containing_cursor
    string used for pagination of containing Vocabs. If included, only containing Vocabs are returned.
  • include_heisigs
    adds Heisig definitions to the Vocabs.
  • include_sentences
    returns a list of sentences chosen by the user to learn with the returned Vocabs
  • sentence_fields
    comma-separated list of Vocab properties to return for the sentences.
  • include_top_mnemonics
    adds the highest rated Mnemonics to the returned Vocabs
  • include_decomps
    returns a list of Decomps for the returned Vocabs
  • decomp_fields
    comma-separated list of Decomps for the returned Vocabs

Response

  • Vocabs
    list of Vocabs. If by id, non existent Vocabs will have null in their place.
  • ContainingVocabs
    list of containing Vocabs. Only included if a containing search was conducted.
  • Sentences
    list of sentence Vocabs for the returned Vocabs list.
  • Decomps
    list of Decomps for the returned Vocabs list.
  • cursor
    string to pass back in future requests for pagination. If not included, there are no more. If included, there probably are more.
  • containingCursor
    string to pass back in future requests for pagination. If not included, there are no more. If included, there probably are more.
  • parsed
    object. If doing a search, returns how 'q' was parsed, for debugging purposes
GET http://legacy.skritter.com/api/v0/vocabs/(id)

Fetches a single Vocab. Include the id in the url.

Parameters

  • fields
    comma-separated list of Vocab properties to return.
  • include_heisig
    adds Heisig definitions to the Vocab.
  • include_sentence
    returns a sentence chosen by the user to learn with the returned Vocab
  • sentence_fields
    comma-separated list of Vocab properties to return for the sentence.
  • include_top_mnemonic
    adds the highest rated Mnemonic to the returned Vocab
  • include_decomp
    returns the Decomps for the returned Vocab
  • decomp_fields
    comma-separated list of Decomps for the returned Vocab
  • include_containing
    if this is a single-character Vocab, returns a list of Vocabs that include the character.
    (default: false)
  • containing_cursor
    string used for pagination of containing Vocabs

Response

  • Vocab
    The requested Vocab.
  • Sentence
    The sentence Vocab referenced by the property sentenceId.
  • Decomp
    The Decomp for the returned Vocab.
  • ContainingVocabs
    list of containing Vocabs. Only included if include_containing is true.
PUT http://legacy.skritter.com/api/v0/vocabs/(id)

Alters custom user properties for an existing Vocab.

Input

One Vocab object with the parameters you would like to set. Only mutable properties will be used; all others will be ignored, and any missing properties will be set to defaults.

Parameters

Same as GET

Response

Same as GET, with one more:

  • Items list of Items that were altered due to changes in the bannedParts property.
GET http://legacy.skritter.com/api/v0/vocabs/(id)/sentences

Returns a list of Vocabs which are sentences for the given Vocab id.

Parameters

  • cursor
    string used for pagination
  • lang
    The language of the Vocabs you want to search or query for.
    (default: user setting)
  • limit
    maximum number of Vocabs to fetch
    (default: 10) (max: 10)
  • fields comma-separated list of Vocab properties to return.
    (default: all)

Response

  • Sentences
    list of sentence Vocabs. May return a few more than the given limit.
  • cursor
    string to pass back in future requests for pagination. If not included, there are no more. If included, there probably are more.

Example: Item to Vocab Fetching

Goal:

Fetch all Vocabs related to the Items you fetched previously.

Solution:

Solution: make id fetches, 100 at a time.


    # given a slew of Items, determine the Vocab ids we need.
    to_fetch = set()
    for item in items:
        for vocab_id in item['vocabIds']:
            to_fetch.add(vocab_id)
    to_fetch = list(to_fetch) # so we can do iteration below

    # prepare the request GET parameters
    params = {
        'bearer_token': token,
        'gzip': False
    }

    vocabs = [] # where we'll be storing the results

    while to_fetch:
        # get the first 100 Vocabs (the max allowed per request)
        subset = to_fetch[:100]
        params['ids'] = ','.join(subset)

        # make repeated calls to fetch everything.
        response = client.get('http://legacy.skritter.com/api/v0/vocabs', params)
        response = json.loads(response.content)

        # gather up the results
        vocabs += response['Vocabs']
        to_fetch = to_fetch[100:]
        print 'fetched %d vocabs, %d left to go' % (len(vocabs), len(to_fetch))

    return vocabs

    

Example: Synchronized Local Data

Goal:

Keep an up-to-date record of all custom data (custom definitions, stars, etc) for the user.

Solution

Use offset to fetch only Vocabs whose user-specific properties have changed since we last checked.


    # given a list of Vocabs we already have, fetch the latest updates
    vocab_dict = dict([(vocab['id'], vocab) for vocab in vocabs])
    offset = max([vocab['changed'] for vocab in vocabs]) if vocabs else 0

    # prepare the request GET parameters
    params = {
        'sort': 'all',
        'gzip': False,
        'offset':offset
    }

    while True:
        # make repeated calls to fetch everything that's new.
        response = client.get('http://legacy.skritter.com/api/v0/vocabs', params)
        response = json.loads(response.content)

        # update and extend our local data
        for vocab in response['Vocabs']:
            vocab_dict[vocab['id']] = vocab

        # continue only if the server says there could be more
        if not 'cursor' in response:
            break

        # for the next iteration, provide the cursor from the last response
        params['cursor'] = response['cursor']

    return vocab_dict

    

Example: Database Searches, Containing Words

Goal:

Search the database for some Vocabs that contain 中

Solution:

Use the 'q' query parameter to search for this word.


    # prepare the request GET parameters
    params = {
        'q': u'中',
        'gzip': False,
        'containing_cursor': True
        'limit':1, # ensure only one result is fetched
    }

    # just get one batch of containing words or sentences
    response = client.get('http://legacy.skritter.com/api/v0/vocabs', params)
    response = json.loads(response.content)

    if not response['Vocabs']:
        print 'word not found'

    else:
        # print search results
        for vocab in response['ContainingVocabs']:
            print vocab['writing'], vocab['reading'], vocab['definitions'].get('en')