Improved queries
[jamaendo] / scripts / query
index 707b48e..ebf97d6 100755 (executable)
@@ -1,27 +1,50 @@
 #!/usr/bin/env python
-from jamaendo.api import DB, Queries
-import sys
+from jamaendo.api import LocalDB, Queries, refresh_dump
+import sys, time
+
+class Refresher(object):
+    def __init__(self):
+        self.done = False
+        self.last_percent = 0
+        print "..."
+    def complete(self):
+        print "Done."
+        self.done = True
+    def progress(self, percent):
+        if percent - self.last_percent >= 5:
+            print "\r%d%%" % (percent),
+            self.last_percent = percent
+
+    def run(self):
+        refresh_dump(self.complete, self.progress, force=False)
+        while not self.done:
+            time.sleep(1)
+
 
 def pprint(x):
     import json
     print json.dumps(x, sort_keys=True, indent=4)
 
 def main():
+    Refresher().run()
 
     query = sys.argv[1]
 
     if query == 'today':
-        result = Queries.albums_today.emit()
+        result = Queries.albums_today()
+        pprint(result)
+    elif query == 'tracks_this_month':
+        result = Queries.tracks_this_month()
         pprint(result)
     elif query == 'artist':
         q = sys.argv[2]
-        db = DB()
+        db = LocalDB()
         db.connect()
         for artist in db.search_artists(q):
             pprint(artist)
     elif query == 'album':
         q = sys.argv[2]
-        db = DB()
+        db = LocalDB()
         db.connect()
         for album in db.search_albums(q):
             pprint(album)