Make VIDEO_ID, API_KEY and COMMENT_REGEX use stdin and not hard-coded values

This commit is contained in:
Benjamin Loison 2023-04-27 00:04:24 +02:00
parent 902d2084f1
commit e19ea59ae4
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -8,26 +8,24 @@ def getContentFromURL(url):
data = json.loads(content)
return data
VIDEO_ID = '5PdEmeopJVQ'
API_KEY = 'AIzaSy...'
PATTERN_REGEX = '76115293'
VIDEO_ID = input('Video id: ')
API_KEY = input('YouTube Data API v3 (empty if use no-key service): ')
COMMENT_REGEX = input('Comment regex')
nextPageToken = ''
pattern = re.compile(PATTERN_REGEX)
commentRegexCompiled = re.compile(COMMENT_REGEX)
def treatComment(comment):
id = comment['id']
textOriginal = comment['snippet']['textOriginal']
if pattern.match(textOriginal):
if commentRegexCompiled.match(textOriginal):
url = f'https://www.youtube.com/watch?v={VIDEO_ID}&lc={id}'
#os.system(f"firefox -new-tab '{url}'")
print(f'{url} {textOriginal}')
while True:
data = getContentFromURL(f'commentThreads?part=snippet,replies&videoId={VIDEO_ID}&maxResults=100&pageToken={nextPageToken}')
#print(data)
for item in data['items']:
#print(item)
snippet = item['snippet']
totalReplyCount = snippet['totalReplyCount']
if totalReplyCount > 5: