Revision 7056140d
Added by dsorber about 12 years ago
| software/bookmark_library/lib/bookmark.py | ||
|---|---|---|
|
|
||
|
def __init__(self, db_conn, id=None, url=None):
|
||
|
|
||
|
# Make sure the DB connection is valid before doing anything
|
||
|
# else
|
||
|
# Make sure the DB connection is valid before doing anything else
|
||
|
if not db_conn:
|
||
|
raise DBConnectionError('Invalid database connection object!')
|
||
|
|
||
| ... | ... | |
|
self.last_visited = 0
|
||
|
self.last_reachable = 0
|
||
|
self.deleted = False
|
||
|
self.category_tags = set()
|
||
|
self.description_tags = set()
|
||
|
|
||
|
# Retrieve an existing bookmark
|
||
|
# Retrieve an existing bookmark if an ID is passed in
|
||
|
if self.id:
|
||
|
db = self._db_conn.cursor()
|
||
|
db.execute(SQL_SELECT_BOOKMARK, (self.id,))
|
||
| software/bookmark_library/lib/tag.py | ||
|---|---|---|
|
import sqlite3
|
||
|
|
||
|
SQL_SELECT_TAG_BY_ID = "SELECT * FROM tags WHERE id=?"
|
||
|
SQL_SELECT_TAG_BY_VALUE = "SELECT * FROM tags WHERE value=?"
|
||
|
|
||
|
|
||
|
class Tag(object):
|
||
|
|
||
|
def __init__(self, db_conn, id=None, value=None):
|
||
|
|
||
|
# Make sure the DB connection is valid before doing anything else
|
||
|
if not db_conn:
|
||
|
raise Exception
|
||
|
#~ raise DBConnectionError('Invalid database connection object!')
|
||
|
|
||
|
self._db_conn = db_conn
|
||
|
|
||
|
# Data attributes
|
||
|
self.id = id
|
||
|
self.value = value
|
||
|
|
||
|
if self.id:
|
||
|
# If an ID was passed in then the tag's value must match the ID
|
||
|
db = self._db_conn.cursor()
|
||
|
db.execute(SQL_SELECT_TAG_BY_ID, (self.id,))
|
||
|
row = db.fetchone()
|
||
|
if not row:
|
||
|
raise Exception
|
||
|
self.value = row[1]
|
||
|
|
||
|
elif self.value:
|
||
|
# If a value was passed in, check to see if it already exists in
|
||
|
# the DB; if so set the ID accordingly
|
||
|
db = self._db_conn.cursor()
|
||
|
db.execute(SQL_SELECT_TAG_BY_VALUE, (self.value,))
|
||
|
row = db.fetchone()
|
||
|
if row:
|
||
|
self.id = int(row[0])
|
||
|
|
||
|
def __str__(self, value):
|
||
|
return repr(self.value)
|
||
Started working on the Tag class.