Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/places.py
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2008-06-12 20:36:12 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2008-06-12 20:36:12 (GMT)
commit707f90daa6d0780cb621e63d3697baaf0996dd6d (patch)
tree2ee14ee0ce7b793bc3e2ab11afe87fbaedf5786f /places.py
parent0b2b5655cbb8955cbb53663272d9c285498d6e2b (diff)
Add a last_visit field
Diffstat (limited to 'places.py')
-rw-r--r--places.py44
1 files changed, 29 insertions, 15 deletions
diff --git a/places.py b/places.py
index 00c6be0..35e2dc0 100644
--- a/places.py
+++ b/places.py
@@ -16,6 +16,7 @@
import os
import sqlite3
+from datetime import datetime
from sugar.activity import activity
@@ -27,6 +28,7 @@ class Place(object):
self.title = None
self.gecko_flags = 0
self.visits = 0
+ self.last_visit = datetime.now()
class SqliteStore(object):
def __init__(self):
@@ -39,10 +41,11 @@ class SqliteStore(object):
cur.execute('select * from sqlite_master where name == "places"')
if cur.fetchone() == None:
cur.execute("""create table places (
- uri TEXT,
- title TEXT,
- gecko_flags INTEGER,
- visits INTEGER
+ uri text,
+ title text,
+ gecko_flags integer,
+ visits integer,
+ last_visit timestamp
);
""")
@@ -53,15 +56,21 @@ class SqliteStore(object):
cur.execute('select * from places where uri like ? or title like ? ' \
'order by visits desc limit 0, 30', (text, text))
- return [_place_from_row(row) for row in cur]
+ result = [self._place_from_row(row) for row in cur]
+
+ cur.close()
+
+ return result
def add_place(self, place):
cur = self._con.cursor()
- cur.execute('insert into places values (?, ?, ?, ?)', \
- (place.uri, place.title, place.gecko_flags, place.visits))
+ cur.execute('insert into places values (?, ?, ?, ?, ?)', \
+ (place.uri, place.title, place.gecko_flags,
+ place.visits, place.last_visit))
self._con.commit()
+ cur.close()
def lookup_place(self, uri):
cur = self._con.cursor()
@@ -69,23 +78,28 @@ class SqliteStore(object):
row = cur.fetchone()
if row:
- return _place_from_row(row)
+ return self._place_from_row(row)
else:
return None
+ cur.close()
+
def update_place(self, place):
cur = self._con.cursor()
- cur.execute('update places set title=?, gecko_flags=?, visits=? ' \
- 'where uri=?', (place.title, place.gecko_flags,
- place.visits, place.uri))
+ cur.execute('update places set title=?, gecko_flags=?, '
+ 'visits=?, last_visit=? where uri=?',
+ (place.title, place.gecko_flags, place.visits,
+ place.last_visit, place.uri))
self._con.commit()
+ cur.close()
-def _place_from_row(row):
- place = Place()
- place.uri, place.title, place.gecko_flags, place.visits = row
- return place
+ def _place_from_row(self, row):
+ place = Place()
+ place.uri, place.title, place.gecko_flags, \
+ place.visits, place.last_visit = row
+ return place
def get_store():
global _store