-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (50 loc) · 1.93 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
# Sample Python code for youtube.commentThreads.insert
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/guides/code_samples#python
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
import urllib2, json
import time
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
url = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCX6OQ3DkcsbYNE6H8uQQuVA&maxResults=10&order=date&type=video&key=AIzaSyAc_wg2XAiKpruMEnHPn9bdvKPN3tGul7c"
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
# os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "client_secret.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(api_service_name, api_version, credentials=credentials)
isPosted = True
while isPosted:
response = urllib2.urlopen(url)
data = json.load(urllib2.urlopen(url))['items'][0]['id']['videoId']
if data != 'wMuYiLby3-s' :
request = youtube.commentThreads().insert(
part="snippet",
body={
"snippet": {
"videoId": data,
"topLevelComment": {
"snippet": {
"textOriginal": "already here!"
}
}
}
}
)
res = request.execute()
print(res)
isPosted = False
else :
time.sleep(1)
isPosted = True
print "Not yet!"
if __name__ == "__main__":
main()