|
@@ -312,6 +312,23 @@ class Db(object):
|
|
|
insert_statement = "INSERT INTO sites (title) VALUES (?)"
|
|
|
self._execute_statement(insert_statement, (name,))
|
|
|
|
|
|
+ def remove_site(self, name):
|
|
|
+ """
|
|
|
+ Removes a site with the specified name to the database.
|
|
|
+
|
|
|
+ :param name: name of the new site
|
|
|
+ :type site: str
|
|
|
+ """
|
|
|
+ site_id = self.get_site_id(name)
|
|
|
+ subscriptions = self._get_subscriptions_by_site_id(site_id)
|
|
|
+ delete_videos = "DELETE FROM videos WHERE subscription_id = ?"
|
|
|
+ delete_subscription = "DELETE FROM SUBSCRIPTIONS WHERE id=?"
|
|
|
+ for sub in subscriptions:
|
|
|
+ self._execute_statement(delete_videos, (sub,))
|
|
|
+ self._execute_statement(delete_subscription, (sub,))
|
|
|
+ delete_site = "DELETE FROM sites WHERE id=?"
|
|
|
+ self._execute_statement(delete_site, (site_id,))
|
|
|
+
|
|
|
def get_site_id(self, name):
|
|
|
"""
|
|
|
Get the ID of a specific site
|
|
@@ -337,3 +354,17 @@ class Db(object):
|
|
|
cursor = self._execute_statement(query)
|
|
|
result = cursor.fetchall()
|
|
|
return result
|
|
|
+
|
|
|
+ def _get_subscriptions_by_site_id(self, site_id):
|
|
|
+ """
|
|
|
+ Retrieves all subscriptions associated with the specified site_id
|
|
|
+ from the database.
|
|
|
+
|
|
|
+ :param site_id: ID of the site
|
|
|
+ :type site_id: int
|
|
|
+ :return: list of subscriptions associated with the site_id
|
|
|
+ :rtype: tuple
|
|
|
+ """
|
|
|
+ query = "SELECT id FROM subscriptions WHERE site=?"
|
|
|
+ cursor = self._execute_statement(query, (site_id,))
|
|
|
+ return cursor.fetchall()
|