Explorar el Código

corrected errors in the database file, made it pep8 clean

Helmut Pozimski hace 10 años
padre
commit
8cb39f6eb7
Se han modificado 1 ficheros con 46 adiciones y 34 borrados
  1. 46 34
      lib_stov/database.py

+ 46 - 34
lib_stov/database.py

@@ -91,44 +91,54 @@ class db(object):
             self.__version = 2
         if int(self.__version) == 2:
             """Changes between version 2 and 3"""
-            self.__ExecuteStatement("ALTER TABLE subscriptions ADD COLUMN disabled \
-            INTEGER DEFAULT 0;")
+            self.__ExecuteStatement("ALTER TABLE subscriptions ADD COLUMN"
+                                    " disabled INTEGER DEFAULT 0;")
             self.__ExecuteStatement("UPDATE subscriptions SET disabled=0;")
-            self.__version=3
+            self.__version = 3
 
     def GetVersion(self):
         """Simple getter method, returns the DB version"""
 
         return self.__version
 
-    def DeleteSubscription(self, id):
-        """Deletes a subscription and all associated videos from the database"""
+    def DeleteSubscription(self, sub_id):
+        """Deletes a subscription and all associated videos from the
+        database
+
+        """
 
         checkquery = "SELECT * FROM subscriptions WHERE id=?"
-        checkresult = self.__ExecuteStatement(checkquery, (id,))
-        if checkresult.fetchall() == []:
+        checkresult = self.__ExecuteStatement(checkquery, (sub_id,))
+        if not checkresult.fetchall():
             raise stov_exceptions.SubscriptionNotFoundException()
         else:
             deletevideos = "DELETE FROM videos WHERE subscription_id=?"
-            self.__ExecuteStatement(deletevideos, (id,))
+            self.__ExecuteStatement(deletevideos, (sub_id,))
             deletesubscription = "DELETE FROM subscriptions WHERE id=?"
-            self.__ExecuteStatement(deletesubscription, (id,))
+            self.__ExecuteStatement(deletesubscription, (sub_id,))
             message = "Subscription deleted successfully!"
         return message
 
-    def GetVideos(self, id):
-        """Gets all videos of a given subscription id from the database and returns them"""
-        video_query = "SELECT id, title, description, ytid, downloaded, failcnt FROM videos WHERE subscription_id=?"
-        cursor = self.__ExecuteStatement(video_query, (id,))
+    def GetVideos(self, video_id):
+        """Gets all videos of a given subscription id from the database and
+        returns them
+
+        """
+        video_query = "SELECT id, title, description, ytid, downloaded, " \
+                      "failcnt FROM videos WHERE subscription_id=?"
+        cursor = self.__ExecuteStatement(video_query, (video_id,))
         result = cursor.fetchall()
         return result
 
     def VideoInDatabase(self, ytid):
-        """Checks if the video with a given youtube id already exists in the database"""
+        """Checks if the video with a given youtube id already exists in the
+        database
+
+        """
         video_query = "SELECT id FROM videos WHERE ytid=?"
         cursor = self.__ExecuteStatement(video_query, (ytid,))
         result = cursor.fetchall()
-        if result == []:
+        if not result:
             return False
         else:
             return True
@@ -146,8 +156,9 @@ class db(object):
 
     def InsertSubscription(self, data):
         """Inserts a subscription with the given data into the database"""
-        subscription_insert = "INSERT INTO subscriptions (title, type, searchstring, \
-                directory, name, disabled) VALUES (?, ?, ?, ?, ?, ?)"
+        subscription_insert = "INSERT INTO subscriptions (title, type, " \
+                              "searchstring, directory, name, disabled) " \
+                              "VALUES (?, ?, ?, ?, ?, ?)"
         self.__ExecuteStatement(subscription_insert, data)
         subscription_getid = "SELECT id from subscriptions where title=?"
         query_cursor = self.__ExecuteStatement(subscription_getid, (data[0],))
@@ -155,48 +166,49 @@ class db(object):
         message = "Subscription sucessfully inserted into database."
         return (message, subscription_id)
 
-    def UpdateVideoDownloadStatus(self, id, status):
+    def UpdateVideoDownloadStatus(self, video_id, status):
         """Updates the download status of a video in the database"""
         update_statement = "UPDATE videos SET downloaded = ? WHERE id = ?"
-        result = self.__ExecuteStatement(update_statement, (status, id))
+        self.__ExecuteStatement(update_statement, (status, video_id))
 
-    def DisableFailedVideo(self, id):
+    def DisableFailedVideo(self, video_id):
         """Disables a video in the database"""
         update_statement = "UPDATE videos SET downloaded = -1 WHERE id = ?"
-        self.__ExecuteStatement(update_statement, (id,))
+        self.__ExecuteStatement(update_statement, (video_id,))
 
-    def UpdateVideoFailCount(self,count, id):
+    def UpdateVideoFailCount(self, count, video_id):
         """Updates the fail count of a video in the database"""
         update_statement = "UPDATE videos SET failcnt = ? WHERE id = ?"
-        self.__ExecuteStatement(update_statement, (count, id))
+        self.__ExecuteStatement(update_statement, (count, video_id))
 
-    def DeleteVideo(self,id):
+    def DeleteVideo(self, video_id):
         """Deletes a video from the database"""
         delete_statement = "DELETE FROM videos where id = ?"
-        self.__ExecuteStatement(delete_statement, (id,))
+        self.__ExecuteStatement(delete_statement, (video_id,))
 
-    def GetSubscription(self, id):
+    def GetSubscription(self, sub_id):
         """Retrieves a specific subscription from the database"""
         sub_query = "SELECT id,title,type,name,searchstring, directory," \
                     "disabled FROM subscriptions where id=?"
-        result_cursor = self.__ExecuteStatement(sub_query, (id,))
+        result_cursor = self.__ExecuteStatement(sub_query, (sub_id,))
         result = result_cursor.fetchall()
         return result
 
-    def GetSubscriptionTitle(self, id):
+    def GetSubscriptionTitle(self, sub_id):
         """Retrieves only the title of a specified subscription from the
         database
 
         """
         title_query = "SELECT title from subscriptions where id=?"
-        result_cursor = self.__ExecuteStatement(title_query, (id,))
+        result_cursor = self.__ExecuteStatement(title_query, (sub_id,))
         result = result_cursor.fetchall()
         return result
 
-    def MarkVideosDownloaded(self, id):
+    def MarkVideosDownloaded(self, video_id):
         """ Marks all videos in a specified subscription as downloaded"""
-        update_statement = "UPDATE videos SET downloaded = 1 WHERE subscription_id =?"
-        self.__ExecuteStatement(update_statement, (id,))
+        update_statement = "UPDATE videos SET downloaded = 1 " \
+                           "WHERE subscription_id =?"
+        self.__ExecuteStatement(update_statement, (video_id,))
 
     def GetSubscriptions(self):
         """Retrieves all subscriptions from the database"""
@@ -210,10 +222,10 @@ class db(object):
         """Vacuums the database, shrinking it in size"""
         self.__ExecuteStatement("VACUUM")
 
-    def ChangeSubscriptionState(self, id, state):
+    def ChangeSubscriptionState(self, sub_id, state):
         """Enables or disables a subscription depending on the parameter
         state
 
         """
         update_statement = "UPDATE subscriptions SET disabled=? WHERE id=?"
-        self.__ExecuteStatement(update_statement, (state,id))
+        self.__ExecuteStatement(update_statement, (state, sub_id))