<commit_before>from importlib import import_module

from django.conf import settings


class Solver(object):
    MISSING = 0
    PENDING = 1
    FAILED  = 2
    SUCCESS = 3

    def _backend(self):
        module_name, backend_name = \
            settings.ASTROBIN_PLATESOLVING_BACKEND.rsplit('.', 1)

        print module_name, backend_name

        module = import_module(module_name)
        return getattr(module, backend_name)()

    # Starts the job and returns an id for later reference
    def solve(self, image_file):
        return self._backend().start(image_file)

    def status(self, submission):
        if submission is None or submission == 0:
            return self.MISSING

        sub_status = self._backend().sub_status(submission)
        status = sub_status.get('status')
        if status == 'fail':
            return self.FAILED

        if 'user_images' in sub_status and not sub_status.get('user_images'):
            return self.MISSING

        jobs = sub_status.get('jobs', [])
        if not jobs:
            return self.PENDING
<commit_msg>Be more robust when dealing with astormetry api.<commit_after>from importlib import import_module

from django.conf import settings


class Solver(object):
    MISSING = 0
    PENDING = 1
    FAILED  = 2
    SUCCESS = 3

    def _backend(self):
        module_name, backend_name = \
            settings.ASTROBIN_PLATESOLVING_BACKEND.rsplit('.', 1)

        print module_name, backend_name

        module = import_module(module_name)
        return getattr(module, backend_name)()

    # Starts the job and returns an id for later reference
    def solve(self, image_file):
        return self._backend().start(image_file)

    def status(self, submission):
        if submission is None or submission == 0:
            return self.MISSING

        sub_status = self._backend().sub_status(submission)
        status = sub_status.get('status', '')
        if status == 'fail':
            return self.FAILED

        if 'user_images' in sub_status and not sub_status.get('user_images'):
            return self.PENDING

        jobs = sub_status.get('jobs', [])
        if not jobs:
            return self.PENDING

{'fraction_non_alphanumeric': 0.08580556823368325, 'fraction_numerical': 0.005476951163852123, 'mean_word_length': 2.4357366771159876, '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': '2474619', 'n_tokens_mistral': 652, 'n_tokens_neox': 617, 'n_words': 175}