<commit_before>import requests
import json
from subprocess import Popen, PIPE
import tempfile
import os

config = {}
with open ('../config/conversion.json') as fp:
  config = json.load(fp)


def to_cml(inchi):
  request = requests.get('%s/service/chemical/cjson/?q=inchi~eq~%s' % (config['baseUrl'], inchi))

  if request.status_code == 200:
    cjson = request.json();
  else:
    return None

  print cjson

  # Call convertion routine
  p = Popen([config['cjsonToCmlPath']], stdin=PIPE, stdout=PIPE, stderr=PIPE)
  stdout, stderr = p.communicate(json.dumps(cjson['results'][0]))

  fd, path = tempfile.mkstemp(suffix='.cml')

  with open(path, 'w') as fp:
    fp.write(str(stdout))

  os.close(fd)

  return path
<commit_msg>Add log statement if REST API can't be accessed<commit_after>import requests
import json
from subprocess import Popen, PIPE
import tempfile
import os
import sys

config = {}
with open ('../config/conversion.json') as fp:
  config = json.load(fp)


def to_cml(inchi):
  request = requests.get('%s/service/chemical/cjson/?q=inchi~eq~%s' % (config['baseUrl'], inchi))

  if request.status_code == 200:
    cjson = request.json();
  else:
    print >> sys.stderr, "Unable to access REST API: %s" % request.status_code
    return None

  # Call convertion routine
  p = Popen([config['cjsonToCmlPath']], stdin=PIPE, stdout=PIPE, stderr=PIPE)
  stdout, stderr = p.communicate(json.dumps(cjson['results'][0]))

  fd, path = tempfile.mkstemp(suffix='.cml')

  with open(path, 'w') as fp:
    fp.write(str(stdout))

  os.close(fd)

  return path

{'fraction_non_alphanumeric': 0.1488817891373802, 'fraction_numerical': 0.005111821086261981, 'mean_word_length': 4.308474576271187, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6463821', 'n_tokens_mistral': 590, 'n_tokens_neox': 557, 'n_words': 137}