Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import urllib.request
- import time
- import json
- app_id = ""
- app_secret = ""
- app_ua = "A bot which will update subreddit sidebar when Ice Poseidon is live"
- username = ""
- password = ""
- channel_id = ""
- google_api_key = ""
- subreddit = ""
- r = praw.Reddit(client_id=app_id,
- client_secret=app_secret,
- user_agent=app_ua,
- username=username,
- password=password)
- is_live = True
- while True:
- youtube_api_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId="
- + channel_id +"&type=video&eventType=live&key=" + google_api_key
- response = urllib.request.urlopen(youtube_api_url)
- youtube_response = json.loads(response.read().decode('utf-8'))
- if youtube_response['pageInfo']['totalResults'] > 0:
- if not is_live:
- settings = r.subreddit(subreddit).mod.settings()
- sidebar_contents = "You are live on Youtube Gaming"
- r.subreddit(subreddit).mod.update(description=sidebar_contents)
- print("Streaming!")
- print("Updating sidebar")
- is_live = True
- else:
- if is_live:
- settings = r.subreddit(subreddit).mod.settings()
- sidebar_contents = "Not live on Youtube Gaming"
- r.subreddit(subreddit).mod.update(description=sidebar_contents)
- print("No stream")
- print("Updating sidebar")
- is_live = False
- time.sleep(300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement