From 103b37030fcd073b5f44b9ddc79da0ce15325a96 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 10 Jun 2019 17:04:06 -0700 Subject: Unsubscribe button on channels if already subscribed --- youtube/subscriptions.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'youtube/subscriptions.py') diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py index b6a4e0e..e12fa0b 100644 --- a/youtube/subscriptions.py +++ b/youtube/subscriptions.py @@ -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) ''' -- cgit v1.2.3