#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Docstring """ from twitchchannelquery import TwitchChannelQuery channel = TwitchChannelQuery() channel.setup('LuppiiMC', 'mysecret') channel.query() if channel.is_online(): print("Channel is online.") print("Stream ID:", channel.get_stream_id()) print("Start time:", channel.get_start_time()) print("Game:", channel.get_game()) print("Title:", channel.get_status()) print("Viewers:", channel.get_viewers()) print("Total views:", channel.get_views()) print("Followers:", channel.get_followers()) else: print("Channel is offline.")
def send_message(url, username, channel, string): """ Docstring """ payload = {"username": username, "channel": channel, "text": string} requests.post(url, json=payload) CONFIG = read_json(CONFIG_FILE) if not CONFIG: CONFIG = default_json('config') if SAVE_CONFIG is True: save_json(CONFIG_FILE, CONFIG) stream = read_json(STREAM_FILE) if not stream: stream = default_json('stream') channel = TwitchChannelQuery() channel.setup(CONFIG["channel"], CONFIG["clientid"]) num_tries = 0 while num_tries < TRIES: channel.query() if channel.is_online: num_tries = TRIES elif not channel.is_online and not stream["online"]: num_tries = TRIES else: num_tries += 1 channel.reset() time.sleep(5) generate_message(channel, stream, STREAM_FILE)