diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/anidb.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/modules/anidb.py b/modules/anidb.py index 83e48ea..df068a4 100644 --- a/modules/anidb.py +++ b/modules/anidb.py @@ -34,13 +34,24 @@ class Module: search = '%%%s%%' % search cur = self.db.cursor() if short: - cur.execute('select * from anidb where aid in (select distinct aid from anidb where title ~~* %s and type in (2, 3)) and type = 1', (search,)) + cur.execute('select * from anidb a where aid in (select distinct aid from anidb where title ~~* %s and type in (2, 3)) and type = 1' + 'order by (select hits from anidb_weights w where a.aid = w.aid)', (search,)) else: - cur.execute('select * from anidb where aid in (select distinct aid from anidb where title ~~* %s) and type = 1', (search,)) + cur.execute('select * from anidb a where aid in (select distinct aid from anidb where title ~~* %s) and type = 1 ' + 'order by (select hits from anidb_weights w where a.aid = w.aid)', (search,)) r = cur.fetchall() cur.close() return [(r[0][0], r[0][3])] if len(r) == 1 else [(x[0], x[3]) for x in r] + def got_hit(self, aid): + cur = self.db.cursor() + cur.execute('update anidb_weights set hits = hits + 1 where aid = %s', (aid,)) + # assume no hits yet + if cur.rowcount == 0: + cur.execute('insert into anidb_weights (aid, hits) values (%s, 1)', (aid,)) + cur.close() + self.db.commit() + def get_info(self, aid): cachepath = os.path.expanduser('~/.fotanidbcache/a%d.dat' % aid) if os.access(cachepath, os.F_OK | os.R_OK) and time.time() - os.stat(cachepath).st_mtime < 60*60*24*7: |