YouTube_captions_search_engine/removeChannelsBeingTreated.py
Benjamin Loison b3779fe49a
Fix #20: YouTube Data API v3 returns rarely suddenly commentsDisabled error which involves an unwanted method switch
Also modified compression command, as I got `sh: 1: zip: Argument list too long` when compressing the 248,868 json files of the French most subscribers channel.
2023-01-08 15:43:27 +01:00

34 lines
890 B
Python
Executable File

#!/usr/bin/python3
import shutil, os
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)
# There are three cases:
# - `channelId`/ exists
# - `channelId`/ and `channelId`.zip exist
# - `channelId`.zip exists
# To manage every case, we need to use two `try`/`except`.
try:
shutil.rmtree(path + channelId)
except:
pass
try:
os.remove(path + channelId + ".zip")
except:
pass