<commit_before>
#!/usr/bin/env python
# encoding: utf-8
"""
tempodb/client.py

Copyright (c) 2012 TempoDB, Inc. All rights reserved.
"""

from dateutil import parser
import requests
import simplejson
import urllib
import urllib2


API_HOST = 'api.tempo-db.com'
API_PORT = 80
API_VERSION = 'v1'


class Database(object):

    def __init__(self, key, secret):
        self.key = key
        self.secret = secret


class Series(object):

    def __init__(self, i, key, attributes={}, tags=[]):
        self.id = i
        self.key = key
        self.attributes = attributes
        self.tags = tags


class DataPoint(object):

    def __init__(self, ts, value):
        self.ts = ts
        self.value = value


class Client(object):

    def __init__(self, key, secret, host=API_HOST, port=API_PORT, secure=True):
        self.key = key
        self.secret = secret
        self.host = host
        self.port = port
        self.secure = secure

    def create_database(self, name=""):
        params = {
            'name': name,
        }
        json = self.request('/database/', method='POST', params=params)
        key = json.get('id', '')
        secret = json.get('password', '')
        database = Database(key, secret)
        return database

    def get_series(self):
        json = self.request('/series/', method='GET')
        series = []
        for s in json:
            i = s.get('id', '')
            key = s.get('key', '')
            attr = s.get('attributes', {})
            tags = s.get('tags', [])
            series.append(Series(i, key, attr, tags))
        return series
    
    def read_id(self, series_id, start, end, interval=None, function=None):
        series_type = 'id'
        series_val = series_id
        return self.read(self, series_type, series_val, start, end, interval, function)

    def read_key(self, series_key, start, end, interval=None, function=None):
        series_type = 'key'
        series_val = series_id
        return self.read(self, series_type, series_val, start, end, interval, function)

    def read(self, series_type, series_val, start, end, interval=None, function=None):
        params = {
            'start': start.isoformat(),<commit_msg>fix bug in read_id and read_key<commit_after>
#!/usr/bin/env python
# encoding: utf-8
"""
tempodb/client.py

Copyright (c) 2012 TempoDB, Inc. All rights reserved.
"""

from dateutil import parser
import requests
import simplejson
import urllib
import urllib2


API_HOST = 'api.tempo-db.com'
API_PORT = 80
API_VERSION = 'v1'


class Database(object):

    def __init__(self, key, secret):
        self.key = key
        self.secret = secret


class Series(object):

    def __init__(self, i, key, attributes={}, tags=[]):
        self.id = i
        self.key = key
        self.attributes = attributes
        self.tags = tags


class DataPoint(object):

    def __init__(self, ts, value):
        self.ts = ts
        self.value = value


class Client(object):

    def __init__(self, key, secret, host=API_HOST, port=API_PORT, secure=True):
        self.key = key
        self.secret = secret
        self.host = host
        self.port = port
        self.secure = secure

    def create_database(self, name=""):
        params = {
            'name': name,
        }
        json = self.request('/database/', method='POST', params=params)
        key = json.get('id', '')
        secret = json.get('password', '')
        database = Database(key, secret)
        return database

    def get_series(self):
        json = self.request('/series/', method='GET')
        series = []
        for s in json:
            i = s.get('id', '')
            key = s.get('key', '')
            attr = s.get('attributes', {})
            tags = s.get('tags', [])
            series.append(Series(i, key, attr, tags))
        return series
    
    def read_id(self, series_id, start, end, interval=None, function=None):
        series_type = 'id'
        series_val = series_id
        return self.read(series_type, series_val, start, end, interval, function)

    def read_key(self, series_key, start, end, interval=None, function=None):
        series_type = 'key'
        series_val = series_id
        return self.read(series_type, series_val, start, end, interval, function)

    def read(self, series_type, series_val, start, end, interval=None, function=None):
        params = {
            'start': start.isoformat(),
{'fraction_non_alphanumeric': 0.12839059674502712, 'fraction_numerical': 0.00406871609403255, 'mean_word_length': 2.3624620060790273, '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': '1730328', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1333, 'n_words': 360}