<commit_before>'''
SDK for the Helios Observations API.  Methods are meant to represent the core
functionality in the developer documentation.  Some may have additional
functionality for convenience.  

@author: mbayer
'''
from heliosSDK.core import SDKCore, IndexMixin, ShowMixin, DownloadImagesMixin
from heliosSDK.utilities import jsonTools
import json
import sys
from threading import Thread
import traceback


# Python 2 and 3 fixes
try:
    from Queue import Queue
except ImportError:
    from queue import Queue
    
try:
    import thread
except ImportError:
    import _thread as thread


class Observations(DownloadImagesMixin, ShowMixin, IndexMixin, SDKCore):
    _CORE_API = 'observations'
    
    def __init__(self):
        pass
        
    def index(self, **kwargs):
        return super(Observations, self).index(**kwargs)
    
    def show(self, observation_id):
        return super(Observations, self).show(observation_id) 
    
    def preview(self, observation_id):
        query_str = '{}/{}/{}/preview'.format(self._BASE_API_URL,
                                        self._CORE_API,
                                        observation_id)
        resp = self._getRequest(query_str,
                               headers={self._AUTH_TOKEN['name']:self._AUTH_TOKEN['value']},
                               verify=self._SSL_VERIFY) 
        
        redirect_url = resp.url[0:resp.url.index('?')]
        
        # Check header for dud statuses. 
        head_check_resp = self._headRequest(redirect_url)
        if 'x-amz-meta-helios' in head_check_resp.headers:
            hdrs = json.loads(head_check_resp.headers['x-amz-meta-helios'])
            
            if hdrs['isOutcast'] or hdrs['isDud'] or hdrs['isFrozen']:
                sys.stderr.write('{} returned a dud image.'.format(redirect_url))
                sys.stderr.flush()
                return {'url' : None}

        return {'url' : redirect_url}<commit_msg>linesep added for stderr output.<commit_after>'''
SDK for the Helios Observations API.  Methods are meant to represent the core
functionality in the developer documentation.  Some may have additional
functionality for convenience.  

@author: mbayer
'''
import json
import os
import sys
from threading import Thread
import traceback

from heliosSDK.core import SDKCore, IndexMixin, ShowMixin, DownloadImagesMixin
from heliosSDK.utilities import jsonTools


# Python 2 and 3 fixes
try:
    from Queue import Queue
except ImportError:
    from queue import Queue
    
try:
    import thread
except ImportError:
    import _thread as thread


class Observations(DownloadImagesMixin, ShowMixin, IndexMixin, SDKCore):
    _CORE_API = 'observations'
    
    def __init__(self):
        pass
        
    def index(self, **kwargs):
        return super(Observations, self).index(**kwargs)
    
    def show(self, observation_id):
        return super(Observations, self).show(observation_id) 
    
    def preview(self, observation_id):
        query_str = '{}/{}/{}/preview'.format(self._BASE_API_URL,
                                        self._CORE_API,
                                        observation_id)
        resp = self._getRequest(query_str,
                               headers={self._AUTH_TOKEN['name']:self._AUTH_TOKEN['value']},
                               verify=self._SSL_VERIFY) 
        
        redirect_url = resp.url[0:resp.url.index('?')]
        
        # Check header for dud statuses. 
        head_check_resp = self._headRequest(redirect_url)
        if 'x-amz-meta-helios' in head_check_resp.headers:
            hdrs = json.loads(head_check_resp.headers['x-amz-meta-helios'])
            
            if hdrs['isOutcast'] or hdrs['isDud'] or hdrs['isFrozen']:
                sys.stderr.write('{} returned a dud image.'.format(redirect_url) + os.linesep)
                sys.stderr.flush()
                return {'url' : None}

        return {'url' : redirect_url}
{'fraction_non_alphanumeric': 0.0922415971695729, 'fraction_numerical': 0.001516300227445034, 'mean_word_length': 2.3204697986577183, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1327737', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1115, 'n_words': 286}