Archive API reference
Package: infocards.archive
The following shows relevant information on the Archive and its functions.
Archive(**kwargs)
Main component of the library, performs all the operations in the database.
Parameters
Common parameters:
db_name
(str): name of the database. Will be passed directly to the database connector. In the case of SQLite, it should be the path to the database file.db_type
(str): eithermysql
,postgres
orsqlite
Specific parameters for MySQL and PostgreSQL connectors:
host
(str): host of the databaseuser
(str): username of the database hostpassword
(str): password used to connect to the hostport
(int): port of the database system
Additional parameters may be required depending on the connector used. Check the documentations for PyMySQL and psycopg2.
Returns
Archive
object.
Raises
ArchiveConnectionException
or ArchiveConfigException
.
Functions
add_card_to_section(cid=0, ctitle="", sid=0, sname="")
Creates a card-section relation.
Parameters
cid
(int): card id used to identify the card for the relationctitle
(str): unique title of the cardsid
(int): section id used to identify the section for the relationsname
(str): unique name of the section
In both cases, either the id or the title/name can be used to perform the identification.
Returns
True
if the relation was created, otherwise False
cards()
Obtain all the cards in the archive
Returns
Generator: CardObj
for each of the cards in the archive.
delete_card(cid=0, title="")
Deletes a card from the archive, as well as all the Relation
s the card was present int.
Parameters
cid
(int): card idtitle
(str): unique card title
Either the id or the title can be used to perform the identification.
Returns
True
if the card was deleted, otherwise False
delete_section(name="", sid=0)
Delete a section from the archive, as well as all the Relation
s the section was present in.
Parameters
name
(str): unique section namesid
(int): section id
Either the name or the id can be used to perform the identification.
Returns
True
if the section was deleted, otherwise False
get_card(cid=0, title="")
Obtains a single card from the archive.
Parameters
cid
(int): card idtitle
(str): unique card title
Either the id or the title can be used to perform the identification.
Returns
CardObj
with the card information or None
if the card was not found.
get_section(name="", sid=0)
Obtains a single section from the archive.
Parameters
name
(str): unique section namesid
(int): section id
Either the name or the id can be used to perform the identification.
Returns
SectionObj
with the section information or None
if the section was not found.
modify_card(card=None, cid=0, ctitle="", title="", desc="", content="", tags="", author="UNKNOWN")
Updates a card in the database.
Parameters
card
(CardObj
): card from which to obtain all the information for the modification (has higher priority than the rest of the parameters)cid
(int): id of the card to modifyctitle
(str): unique title of the card to modifytitle
(str): new title for the carddesc
(str): new description for the cardcontent
(str): new content for the cardtags
(str): whitespace separated tags for the cardauthor
(str): name of the author of the modification
Note that if card
is not used, only the parameters that have been specificed will be overwritten. The modification timestamp of the card will be automatically set to the current date and time.
Returns
New CardObj
instance of the updated card.
Raises
ArchiveIntegrityException
new_card(title, desc, content, tags, author="UNKNOWN")
Creates a new card in the archive.
Parameters
title
(str): unique title for the new carddesc
(str): short description for the cardcontent
(str): main content of the card, may be multilinetags
(str): whitespace separated tags for the cardauthor
(str): name of the author of the new card
The modification timestamp will be automatically set to the current date and time.
Returns
New CardObj
instance of the created card.
Raises
ArchiveIntegrityException
new_section(name)
Creates a new section in the archive.
Parameters
name
(str): unique name for the new section
Returns
New SectionObj
instance of the created section.
Raises
ArchiveIntegrityException
remove_card_from_section(cid=0, ctitle="", sid=0, sname="")
Removes a card-section relation.
Parameters
cid
(int): card id used to identify the card for the relationctitle
(str): unique title of the cardsid
(int): section id used to identify the section for the relationsname
(str): unique name of the section
In both cases, either the id or the title/name can be used to perform the identification.
Returns
True
if the relation was deleted, otherwise False
rename_section(newname, oldname="", sid=0)
Rename a section of the archive
Parameters
newname
(str): new name for the section (should not exist already)oldname
(str): old name of the section, used for identificationsid
(int): section id
In order to identify the section, either its old name or id can be used.
Returns
New SectionObj
instance with the updated name.
Raises
ArchiveIntegrityException
search(query, sname="", sid=0, likelihood=80, relevance=50)
Perform a search in the archive to find relevant cards. By default, it performs the search through all the cards of the archive, but it is also possible to narrow the search to those cards present in the specified section.
Parameters
query
(str): whitespace separated query termssname
(str): name of the section in which to perform the searchsid
(int): unique id of the section in which to perform the searchlikelihood
(int): percentage for which two words are considered similarrelevance
(int): percentage of query terms that a card must contain for it to be considered relevant to the search.
Returns
Generator: cards relevant to the search, or an empty list if no cards were found.
sections()
Obtain all the sections in the archive
Returns
Generator: SectionObj
for each of the sections in the archive.