<commit_before>import json
import requests
import os
import sys
from dateutil.parser import parse
from datetime import datetime, timedelta, date
import pytz
import base64
import rollbar

class TimeEntryEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.isoformat()

        if isinstance(obj, TimeEntry):
            return obj.__dict__

def truncateSeconds(dt):
    return datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, tzinfo = dt.tzinfo)

def roundToQuarterHour(dt):
    roundTo = int((dt.minute + 7.5) / 15) * 15
    m = roundTo - dt.minute
    return dt + timedelta(minutes = m)

class TimeEntry:
    def __init__(self, start = None, stop = None, duronly = None, pid = None,
            billable = None, guid = None, at = None, wid = None,
            id = None, uid = None, description=None, duration=None, tags=None):
        self.description = description
        self.tags = tags

        if start != None:
            self.start = roundToQuarterHour(truncateSeconds(parse(start)))

        if stop != None:
            self.stop = roundToQuarterHour(truncateSeconds(parse(stop)))

        if duration != None and duration > 0:
            self.duration = duration
        elif start != None and stop != None:
            self.duration = (self.stop - self.start).seconds

        self.duronly = duronly
        self.pid = pid
        self.billable = billable
        self.guid = guid
        self.at = at
        self.wid = wid
        self.id = id
        self.uid = uid

    def __repr__(self):
        # return "{0} - {1} - {2}".format(self.start, getattr(self, 'stop', None), self.duration)
        return "{0}".format(self.__dict__)

def getHeaders():
    api_key = os.environ.get("TOGGL_API_KEY")
    if not api_key:
        print("'TOGGL_API_KEY' environment variable not set. Please set this variable to continue")
        return

    base64Token = base64.b64encode("{0}:api_token".format(api_key).encode()).decode()
    return { "Authorization" : "Basic " + base64Token }
<commit_msg>- Set duration based on new start and stop times<commit_after>import json
import requests
import os
import sys
from dateutil.parser import parse
from datetime import datetime, timedelta, date
import pytz
import base64
import rollbar

class TimeEntryEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.isoformat()

        if isinstance(obj, TimeEntry):
            return obj.__dict__

def truncateSeconds(dt):
    return datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, tzinfo = dt.tzinfo)

def roundToQuarterHour(dt):
    roundTo = int((dt.minute + 7.5) / 15) * 15
    m = roundTo - dt.minute
    return dt + timedelta(minutes = m)

class TimeEntry:
    def __init__(self, start = None, stop = None, duronly = None, pid = None,
            billable = None, guid = None, at = None, wid = None,
            id = None, uid = None, description=None, duration=None, tags=None):
        self.description = description
        self.tags = tags

        if start != None:
            self.start = roundToQuarterHour(truncateSeconds(parse(start)))

        if stop != None:
            self.stop = roundToQuarterHour(truncateSeconds(parse(stop)))

        if start != None and stop != None:
            self.duration = (self.stop - self.start).seconds

        self.duronly = duronly
        self.pid = pid
        self.billable = billable
        self.guid = guid
        self.at = at
        self.wid = wid
        self.id = id
        self.uid = uid

    def __repr__(self):
        # return "{0} - {1} - {2}".format(self.start, getattr(self, 'stop', None), self.duration)
        return "{0}".format(self.__dict__)

def getHeaders():
    api_key = os.environ.get("TOGGL_API_KEY")
    if not api_key:
        print("'TOGGL_API_KEY' environment variable not set. Please set this variable to continue")
        return

    base64Token = base64.b64encode("{0}:api_token".format(api_key).encode()).decode()
    return { "Authorization" : "Basic " + base64Token }

{'fraction_non_alphanumeric': 0.11238420282788883, 'fraction_numerical': 0.010482691370063383, 'mean_word_length': 2.583406113537118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2169571', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1226, 'n_words': 349}