<commit_before><commit_msg>Add getHWND/getAllWindows utility functions for bots.<commit_after>import subprocess

# criteria: dictionary that has key/values to match against.
# e.g. {"wm_class": "Navigator.Firefox"}
def getHWND(criteria):
  windows = getAllWindows()
  for window in windows:
    if criteria.items() <= window.items():
      return window
  return None


def getAllWindows():
  windows = []
  with subprocess.Popen(["wmctrl", "-l", "-p", "-x"], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
    for line in p.stdout:
      tokens = line.split()
      windows.append({"hwnd": tokens[0], "workspace": tokens[1], "pid": tokens[2], "wm_class": tokens[3], "title": " ".join(tokens[5:])})
  return windows

{'fraction_non_alphanumeric': 0.16054421768707483, 'fraction_numerical': 0.00816326530612245, 'mean_word_length': 4.575757575757576, 'pattern_counts': {'":': 6, '<': 4, '<?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': '742566', 'n_tokens_mistral': 240, 'n_tokens_neox': 239, 'n_words': 64}