Skip to content

Commit

Permalink
Merge pull request #16 from Project-Coda/dev
Browse files Browse the repository at this point in the history
3.0.1
  • Loading branch information
ikifar2012 authored Jul 15, 2022
2 parents 410599f + f558902 commit 7758633
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions now-playing.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-


'''
"""
This code manages the now playing text and YouTube Live chatbot for the Radio Coda Stream
Author: Matheson Steplock
Adapted from: https://developers.google.com/explorer-help/code-samples#python
'''
"""

import os
import random
Expand Down Expand Up @@ -35,6 +35,18 @@
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
def refresh_credentials():
"""
Refreshes the credentials
"""
global credentials
if credentials is None:
credentials = Credentials.from_authorized_user_file(token_file)
else:
credentials.refresh(Request())
return credentials


if os.path.exists(token_file):
credentials = Credentials.from_authorized_user_file(token_file, scopes)
# If there are no (valid) credentials available, let the user log in.
Expand Down Expand Up @@ -67,15 +79,18 @@ def index():
if "link" in req_data["now_playing"]["song"]["custom_fields"]:
link = req_data["now_playing"]["song"]["custom_fields"]["link"]
update_now_playing(text)
send_message(create_now_playing_text(text, link))
now_playing_text = create_now_playing_text(text, link)
send_message(now_playing_text)
global message_count
print("Message count:" + message_count)
if message_count > 2:
send_message(random_message())
message_count = 0
refresh_credentials()
else:
message_count += 1

return '{"success":"true"}'
return 'OK Updated ' + str(now_playing_text)


def random_message():
Expand Down

0 comments on commit 7758633

Please # to comment.