From dde52da8c897246dea0f2e4b5bd5045a4abba33c Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Wed, 4 Jan 2023 02:41:07 +0100 Subject: [PATCH] Add `{removeChannelsBeingTreated, findTreatedChannelWithMost{Comments, Subscribers}}.py` --- findTreatedChannelWithMostComments.py | 16 ++++++++++++++++ findTreatedChannelWithMostSubscribers.py | 23 +++++++++++++++++++++++ removeChannelsBeingTreated.py | 23 +++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 findTreatedChannelWithMostComments.py create mode 100644 findTreatedChannelWithMostSubscribers.py create mode 100644 removeChannelsBeingTreated.py diff --git a/findTreatedChannelWithMostComments.py b/findTreatedChannelWithMostComments.py new file mode 100644 index 0000000..f7fd69b --- /dev/null +++ b/findTreatedChannelWithMostComments.py @@ -0,0 +1,16 @@ +#!/usr/bin/python3 + +infix = ' comments were found for this channel.' +biggestCommentsCount = 0 + +with open('nohup.out') as f: + lines = f.read().splitlines() + for line in lines: + if infix in line: + #print(line) + commentsCount = int(line.split(': ')[-1].split(infix)[0]) + #print(commentsCount) + if biggestCommentsCount < commentsCount: + biggestCommentsCount = commentsCount + +print(biggestCommentsCount) diff --git a/findTreatedChannelWithMostSubscribers.py b/findTreatedChannelWithMostSubscribers.py new file mode 100644 index 0000000..0a452cf --- /dev/null +++ b/findTreatedChannelWithMostSubscribers.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 + +import os, requests, json + +channelIds = next(os.walk('channels/'))[1] +maxResults = 50 + +channelIdsChunks = [channelIds[i : i + maxResults] for i in range(0, len(channelIds), maxResults)] +mostSubscriberCount = 0 +mostSubscriberChannel = None + +for channelIds in channelIdsChunks: + url = 'https://yt.lemnoslife.com/noKey/channels?part=statistics&id=' + ','.join(channelIds) + content = requests.get(url).text + data = json.loads(content) + items = data['items'] + for item in items: + subscriberCount = int(item['statistics']['subscriberCount']) + if mostSubscriberCount < subscriberCount: + mostSubscriberCount = subscriberCount + mostSubscriberChannel = item['id'] + +print(mostSubscriberChannel, mostSubscriberCount) diff --git a/removeChannelsBeingTreated.py b/removeChannelsBeingTreated.py new file mode 100644 index 0000000..7dcb8bf --- /dev/null +++ b/removeChannelsBeingTreated.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 + +import shutil + +infix = ': Treating channel ' +path = 'channels/' + +threads = {} + +with open('nohup.out') as f: + lines = f.read().splitlines() + for line in lines: + if infix in line: + #print(line) + threadId = line.split(': ')[1] + channelId = line.split(infix)[1].split(' (')[0] + threads[threadId] = channelId + for threadId in threads: + channelId = threads[threadId] + print(threadId, channelId) + shutil.rmtree(path + channelId) + +