<commit_before># Copyright 2012 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from reap.api.base import ReapBase, parse_time

class Timesheet(ReapBase):
    def __init__(self, base_uri, username, password):
        self.base_uri = base_uri
        self.username = username
        self.password = password
        login_response = self.get_request('account/who_am_i')
        if not login_response:
            raise ValueError('Unable to login with given info.')
        self.id = login_response['user']['id']

    def projects(self):
        projects_response = self.get_request('daily')
        projects = [Project(pjson) for pjson in projects_response['projects']]
        return projects

    def entries(self):
        entries_response = self.get_request('daily')
        entries = Entries(self, entries_response['day_entries'])
        return entries

    def create_entry(self, project_id, task_id, hours = 0, notes = ''):
        entry = {
            'project_id': project_id,
            'task_id': task_id,
            'hours': hours,
            'notes': notes,
        }
        response = self.post_request('daily/add', entry)
        if response:
            return Entry(self, response)

class Project:
    def __init__(self, json):
        self.name = json['name']
        self.id = json['id']
        self.client = json['client']
        self.task_json = json['tasks']

    def tasks(self):
        tasks = [Task(self, tjson) for tjson in self.task_json]
        return tasks

class Task:
    def __init__(self, project, json):
        self.name = json['name']
        self.id = json['id']
        self.billable = json['billable']
        self.project = project

class Entries:
    def __init__(self, ts, json):
        self.ts = ts
        self.entry_list = [Entry(ts, ejson) for ejson in json]

    def __iter__(self):
        return iter(self.entry_list)

    def __len__(self):
        return len(self.entry_list)

class Entry:
    def __init__(self, ts, json):
        self.ts = ts
        self.__parse_json(json)

    def __parse_json(self, json):
        self.id = json['id']
        self.spent_at = json['spent_at']<commit_msg>Got rid of Entries middleman class. Timesheet.entries() now returns a list.<commit_after># Copyright 2012 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from reap.api.base import ReapBase, parse_time

class Timesheet(ReapBase):
    def __init__(self, base_uri, username, password):
        self.base_uri = base_uri
        self.username = username
        self.password = password
        login_response = self.get_request('account/who_am_i')
        if not login_response:
            raise ValueError('Unable to login with given info.')
        self.id = login_response['user']['id']

    def projects(self):
        projects_response = self.get_request('daily')
        projects = [Project(pjson) for pjson in projects_response['projects']]
        return projects

    def entries(self):
        entries_response = self.get_request('daily')
        entries = [Entry(self, ejson) for ejson in entries_response['day_entries']]
        return entries

    def create_entry(self, project_id, task_id, hours = 0, notes = ''):
        entry = {
            'project_id': project_id,
            'task_id': task_id,
            'hours': hours,
            'notes': notes,
        }
        response = self.post_request('daily/add', entry)
        if response:
            return Entry(self, response)

class Project:
    def __init__(self, json):
        self.name = json['name']
        self.id = json['id']
        self.client = json['client']
        self.task_json = json['tasks']

    def tasks(self):
        tasks = [Task(self, tjson) for tjson in self.task_json]
        return tasks

class Task:
    def __init__(self, project, json):
        self.name = json['name']
        self.id = json['id']
        self.billable = json['billable']
        self.project = project

class Entry:
    def __init__(self, ts, json):
        self.ts = ts
        self.__parse_json(json)

    def __parse_json(self, json):
        self.id = json['id']
        self.spent_at = json['spent_at']
{'fraction_non_alphanumeric': 0.10452690887895862, 'fraction_numerical': 0.003497182824946571, 'mean_word_length': 2.687679083094556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6855714', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1458, 'n_words': 462}