Unsubscribe button on channels if already subscribed

This commit is contained in:
James Taylor
2019-06-10 17:04:06 -07:00
parent e7989db931
commit 103b37030f
4 changed files with 61 additions and 9 deletions

View File

@@ -68,6 +68,20 @@ def with_open_db(function, *args, **kwargs):
with connection as cursor:
return function(cursor, *args, **kwargs)
def is_subscribed(channel_id):
if not os.path.exists(database_path):
return False
with open_database() as connection:
with connection as cursor:
result = cursor.execute('''SELECT EXISTS(
SELECT 1
FROM subscribed_channels
WHERE yt_channel_id=?
LIMIT 1
)''', [channel_id]).fetchone()
return bool(result[0])
def _subscribe(cursor, channels):
''' channels is a list of (channel_id, channel_name) '''