<commit_before>#!/usr/bin/python
import time, sys, os, subprocess, re

import xerox

def clip_str_to_path_line(clip_str):
  clip_str = clip_str.replace('http://localhost:5000', os.path.expanduser('~/Dropbox/CardBrew'))
  if clip_str.count('\n') > 1:
    return
                    #        file extension
                    #     path      |
                    #      |        |
  match = re.search('[^\w](/[^@^:]+\.[a-z]{2,3})[^:]*(line.*?|:)([0-9]+)', clip_str)
  if match:
    return ':'.join([match.group(1), match.group(3)])

if __name__ == '__main__':
  clip_str = None
  while True:
    prev_value = clip_str
    clip_str = xerox.paste()
    if prev_value is not None and clip_str != prev_value:
      print 'new value:', clip_str
      path_line = clip_str_to_path_line(clip_str)
      if path_line:
        print 'got path_line:', path_line
        subprocess.Popen(['/usr/local/bin/atom', path_line])
    time.sleep(0.5)
<commit_msg>switch back to pyperclip; don't die on UnicodeDecodeError<commit_after>#!/usr/bin/python
import time, sys, os, subprocess, re

import pyperclip

def clip_str_to_path_line(clip_str):
  clip_str = clip_str.replace('http://localhost:5000', os.path.expanduser('~/Dropbox/CardBrew'))
  if clip_str.count('\n') > 1:
    return
                    #        file extension
                    #     path      |
                    #      |        |
  match = re.search('[^\w](/[^@^:]+\.[a-z]{2,3})[^:]*(line.*?|:)([0-9]+)', clip_str)
  if match:
    return ':'.join([match.group(1), match.group(3)])

if __name__ == '__main__':
  clip_str = None
  while True:
    prev_value = clip_str
    try:
      clip_str = pyperclip.paste()
      # (the value that was initially on clipboard before running script)
      if prev_value is None:
        prev_value = clip_str
    except UnicodeDecodeError:
      pass
    else:
      if clip_str != prev_value:
        print 'new value:', clip_str
        path_line = clip_str_to_path_line(clip_str)
        if path_line:
          print 'got path_line:', path_line
          subprocess.Popen(['/usr/local/bin/atom', path_line])
    time.sleep(0.5)

{'fraction_non_alphanumeric': 0.15073009891662742, 'fraction_numerical': 0.012246820536975978, 'mean_word_length': 2.436893203883495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '281450', 'n_tokens_mistral': 766, 'n_tokens_neox': 736, 'n_words': 149}