<commit_before>#!/usr/bin/env python

import argparse
import autopy
import socket
import time

from sockutil import set_tcp_keepalive

def handleCommand(command):
  # print command # XXX
  if command == 'D':
    print 'Page Down'
    # Cast to long needed because of autopy bug
    # https://github.com/msanders/autopy/issues/67
    autopy.key.tap(long(autopy.key.K_PAGEDOWN))
  elif command == 'U':
    print 'Page Up'
    autopy.key.tap(long(autopy.key.K_PAGEUP))

def connectAndListen(host, port):
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  # Turn on keepalive with a 1 second timeout, 1 attempt (not set on Mac and
  # Windows), and 1 second interval between tries (not set on Mac). Small values
  # because some network noise is better than a performance ruined by a page
  # that didn't turn.
  set_tcp_keepalive(sock, True, 1, 1, 1)
  try:
    sock.connect((host, port))
  except socket.error as error:
    print 'Failed to connect:', error
    return
  print 'Connected'
  while True:<commit_msg>Fix autopy calls on Windows<commit_after>#!/usr/bin/env python

import argparse
import autopy
import socket
import time

from sockutil import set_tcp_keepalive

def handleCommand(command):
  # print command # XXX
  if command == 'D':
    print 'Page Down'
    autopy.key.tap(autopy.key.K_PAGEDOWN)
  elif command == 'U':
    print 'Page Up'
    autopy.key.tap(autopy.key.K_PAGEUP)

def connectAndListen(host, port):
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  # Turn on keepalive with a 1 second timeout, 1 attempt (not set on Mac and
  # Windows), and 1 second interval between tries (not set on Mac). Small values
  # because some network noise is better than a performance ruined by a page
  # that didn't turn.
  set_tcp_keepalive(sock, True, 1, 1, 1)
  try:
    sock.connect((host, port))
  except socket.error as error:
    print 'Failed to connect:', error
    return
  print 'Connected'
  while True:
{'fraction_non_alphanumeric': 0.09450436569080636, 'fraction_numerical': 0.007190549563430919, 'mean_word_length': 3.762836185819071, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6571204', 'n_tokens_mistral': 654, 'n_tokens_neox': 628, 'n_words': 222}