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

import requests
import time
import os
import sys


def dump_info(endpoint, task_id):
    log_request_url = '%s/tasks/%d/logs' % (endpoint, task_id)
    task_request_url = '%s/tasks/%d' % (endpoint, task_id)

    task_info = requests.get(task_request_url)

    if (task_info.status_code >= 200 and task_info.status_code < 300):
        task_status = task_info.json['task']['state']

    log = requests.get(log_request_url)
    log_data = None

    if (log.status_code >= 200 and log.status_code < 300):
        log_data = log.json['log']

    os.system('clear')
    print 'Task %d state: %s\n' % (task_id, task_status)

    if log_data is not None:
        print log_data
    else:
        print 'Error returning log info'
        return False

    if task_status != 'running':
        return False

    return True

endpoint = os.environ.get('ROUSH_ENDPOINT', 'http://localhost:8080')
if len(sys.argv) < 2:
    print "first argument is task to watch"
    sys.exit(1)

task_id = int(sys.argv[1])

while dump_info(endpoint, task_id):
    time.sleep(10)<commit_msg>real logtailer<commit_after>#!/usr/bin/env python

import requests
import time
import os
import sys
import socket
import urlparse


def dump_info(endpoint, task_id):
    log_request_url = '%s/tasks/%d/logs' % (endpoint, task_id)
    task_request_url = '%s/tasks/%d' % (endpoint, task_id)

    task_info = requests.get(task_request_url)

    if (task_info.status_code >= 200 and task_info.status_code < 300):
        task_status = task_info.json['task']['state']

    log = requests.get(log_request_url + '?watch')

    if (log.status_code >= 200 and log.status_code < 300):
        txid = log.json['request']
    else:
        print 'error getting transaction'
        sys.exit(1)

    urlinfo = urlparse.urlparse(endpoint)

    fd = socket.socket()
    fd.connect((urlinfo.hostname, urlinfo.port))
    fd.send('GET /tasks/%d/logs/%s HTTP/1.0\n\n' % (task_id, txid))

    linedata = []

    while linedata == []:
        data = fd.recv(4096)
        linedata = data.split('\n')

        while(len(linedata) > 0 and \
                  linedata[0] != '' and \
                  linedata[0] != '\r'):
            linedata.pop(0)

    sys.stdout.write('\n'.join(linedata))

    while True:
        data = fd.recv(1024)
        if data == '':
            break;

        sys.stdout.write(data)

    fd.close()


endpoint = os.environ.get('ROUSH_ENDPOINT', 'http://localhost:8080')
if len(sys.argv) < 2:
    print "first argument is task to watch"
    sys.exit(1)

task_id = int(sys.argv[1])

dump_info(endpoint, task_id)
{'fraction_non_alphanumeric': 0.13799694189602446, 'fraction_numerical': 0.02102446483180428, 'mean_word_length': 2.803779069767442, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, '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': '3584153', 'n_tokens_mistral': 950, 'n_tokens_neox': 888, 'n_words': 199}