mirror of
https://github.com/ankitects/anki.git
synced 2025-11-12 07:37:11 -05:00
- media is no longer hashed, and instead stored in the db using its original
name
- when adding media, its checksum is calculated and used to look for
duplicates
- duplicate filenames will result in a number tacked on the file
- the size column is used to count card references to media. If media is
referenced in a fact but not the question or answer, the count will be zero.
- there is no guarantee media will be listed in the media db if it is unused
on the question & answer
- if rebuildMediaDir(delete=True), then entries with zero references are
deleted, along with any unused files in the media dir.
- rebuildMediaDir() will update the internal checksums, and set the checksum
to "" if a file can't be found
- rebuildMediaDir() is a lot less destructive now, and will leave alone
directories it finds in the media folder (but not look in them either)
- rebuildMediaDir() returns more information about the state of media now
- the online and mobile clients will need to to make sure that when
downloading media, entries with no checksum are non-fatal and should not
abort the download process.
- the ref count is updated every time the q/a is updated - so the db should be
up to date after every add/edit/import
- since we look for media on the q/a now, card templates like '<img
src="{{{field}}}">' will work now
- export original files as gone as it is not needed anymore
- move from per-model media URL to deckVar. downloadMissingMedia() uses this
now. Deck subscriptions will have to be updated to share media another way.
- pass deck in formatQA, as latex support is going to change
58 lines
1 KiB
Python
58 lines
1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
|
|
|
"""\
|
|
Anki (libanki)
|
|
====================
|
|
|
|
Open a deck:
|
|
|
|
deck = anki.DeckStorage.Deck(path)
|
|
|
|
Get a card:
|
|
|
|
card = deck.getCard()
|
|
if not card:
|
|
# deck is finished
|
|
|
|
Show the card:
|
|
|
|
print card.question, card.answer
|
|
|
|
Answer the card:
|
|
|
|
deck.answerCard(card, ease)
|
|
|
|
Edit the card:
|
|
|
|
fields = card.fact.model.fieldModels
|
|
for field in fields:
|
|
card.fact[field.name] = "newvalue"
|
|
card.fact.setModified(textChanged=True, deck=deck)
|
|
deck.setModified()
|
|
|
|
Get all cards via ORM (slow):
|
|
|
|
from anki.cards import Card
|
|
cards = deck.s.query(Card).all()
|
|
|
|
Get all q/a/ids via SQL (fast):
|
|
|
|
cards = deck.s.all("select id, question, answer from cards")
|
|
|
|
Save & close:
|
|
|
|
deck.save()
|
|
deck.close()
|
|
"""
|
|
__docformat__ = 'restructuredtext'
|
|
|
|
try:
|
|
__import__('pkg_resources').declare_namespace(__name__)
|
|
except ImportError:
|
|
pass
|
|
|
|
version = "1.1.7"
|
|
|
|
from anki.deck import DeckStorage
|