<commit_before>#!/usr/bin/python

import logging
import pychromecast

class CachedChromecastController(object):
  def __init__(self):
    self._chromecasts = []

  def discover_chromecasts(self):
    logging.info("Discovering Chromecasts ...")
    try:
      chromecasts = pychromecast.get_chromecasts()
    except pychromecast.PyChromecastError:
      logging.exception("Could not discover Chromecasts")
      return

    if chromecasts:
      self._chromecasts = chromecasts

  def _get_chromecast(self, chromecast_name):
    for chromecast in self._chromecasts:
      if chromecast_name == chromecast.name:
        return chromecast
    else:
      logging.error("Could not find Chromecast \"%s\"" % chromecast_name)
      return None
   
  def start_chromecast_app(self, chromecast_name, app_id):
    chromecast = self._get_chromecast(chromecast_name)
    if not chromecast:
      return False

    try:
      chromecast.wait()
      if chromecast.status:
        if chromecast.status.is_stand_by:
          chromecast.quit_app()
        logging.info("Starting app %s on Chromecast: %s" % (
            app_id, chromecast_name))
        chromecast.start_app(app_id)
        return True
    except pychromecast.PyChromecastError:<commit_msg>Don't attempt to independently quit running app.<commit_after>#!/usr/bin/python

import logging
import pychromecast

class CachedChromecastController(object):
  def __init__(self):
    self._chromecasts = []

  def discover_chromecasts(self):
    logging.info("Discovering Chromecasts ...")
    try:
      chromecasts = pychromecast.get_chromecasts()
    except pychromecast.PyChromecastError:
      logging.exception("Could not discover Chromecasts")
      return

    if chromecasts:
      self._chromecasts = chromecasts

  def _get_chromecast(self, chromecast_name):
    for chromecast in self._chromecasts:
      if chromecast_name == chromecast.name:
        return chromecast
    else:
      logging.error("Could not find Chromecast \"%s\"" % chromecast_name)
      return None
   
  def start_chromecast_app(self, chromecast_name, app_id):
    chromecast = self._get_chromecast(chromecast_name)
    if not chromecast:
      return False

    try:
      chromecast.wait()
      if chromecast.status:
        logging.info("Starting app %s on Chromecast: %s" % (
            app_id, chromecast_name))
        chromecast.start_app(app_id)
        return True
    except pychromecast.PyChromecastError:
{'fraction_non_alphanumeric': 0.08411596570028583, 'fraction_numerical': 0.0, 'mean_word_length': 3.209621993127148, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '518225', 'n_tokens_mistral': 837, 'n_tokens_neox': 794, 'n_words': 162}