<commit_before>import json
import datetime

import flask
from flask import Flask
import requests

app = Flask(__name__)


class Weekly(object):

    def __init__(self):
        self.api_token='1<PASSWORD>'
        self.wsid = 737293
        self.url = 'https://toggl.com/reports/api/v2/weekly'

    def get_dates(self):
        today = datetime.date.today()
        start_week = today - datetime.timedelta(days=today.weekday())
        end_week = start_week + datetime.timedelta(days=6)
        return (start_week, end_week)

    def format_date(self, date):
        return date.strftime('%Y-%m-%d')

    def build_url(self, since, until):
        params = '?workspace_id={wsid}&since={since}&until={until}&user_agent=testing'.format(
            wsid=self.wsid,
            since=since,
            until=until
        )
        return self.url + params

    def fetch(self):
        since, until = self.get_dates()
        since = self.format_date(since)
        until = self.format_date(until)
        headers = {'content-type': 'application/json'}
        auth = requests.auth.HTTPBasicAuth(self.api_token, 'api_token')
        url = self.build_url(since, until)
        r = requests.get(url, headers=headers, auth=auth)
        return json.loads(r.content)

    def billable(self):
        report = self.fetch()
        return report['total_billable']


def ms_to_hours(ms):
    return (ms/1000)/3600


def format_ms_to_hours_minutes(ms):
    s = ms/1000
    m, s = divmod(s, 60)
    h, m = divmod(m, 60)
    return '{0} h {1} min'.format(h, m)


@app.route("/")
def total_billable_this_week():
    w = Weekly()
    billable_hours = ms_to_hours(w.billable())
    content = {
        "item": [
            {
                "value": billable_hours,
                "text": "Billable hours this week"
            }
        ]
    }
    return flask.jsonify(**content)

if __name__ == "__main__":
    app.run(debug=True)<commit_msg>Add estimated revenue this week<commit_after>import json
import datetime

import flask
from flask import Flask
import requests

app = Flask(__name__)


class Weekly(object):

    def __init__(self):
        self.api_token='<PASSWORD>'
        self.wsid = 737293
        self.url = 'https://toggl.com/reports/api/v2/weekly'

    def get_dates(self):
        today = datetime.date.today()
        start_week = today - datetime.timedelta(days=today.weekday())
        end_week = start_week + datetime.timedelta(days=6)
        return (start_week, end_week)

    def format_date(self, date):
        return date.strftime('%Y-%m-%d')

    def build_url(self, since, until):
        params = '?workspace_id={wsid}&since={since}&until={until}&user_agent=testing'.format(
            wsid=self.wsid,
            since=since,
            until=until
        )
        return self.url + params

    def fetch(self):
        since, until = self.get_dates()
        since = self.format_date(since)
        until = self.format_date(until)
        headers = {'content-type': 'application/json'}
        auth = requests.auth.HTTPBasicAuth(self.api_token, 'api_token')
        url = self.build_url(since, until)
        r = requests.get(url, headers=headers, auth=auth)
        return json.loads(r.content)

    def billable(self):
        report = self.fetch()
        return report['total_billable']


def ms_to_hours(ms):
    return (ms/1000)/3600


def format_ms_to_hours_minutes(ms):
    s = ms/1000
    m, s = divmod(s, 60)
    h, m = divmod(m, 60)
    return '{0} h {1} min'.format(h, m)


def build_content_for_number_widget(value, text):
    content = {
        "item": [
            {
                "value": value,
                "text": text,
            }
        ]
    }
    return content


@app.route("/")
def total_billable_this_week():
    w = Weekly()
    billable_hours = ms_to_hours(w.billable())
    content = build_content_for_number_widget(billable_hours, 'Billable hours this week')
    return flask.jsonify(**content)


@app.route("/revenue-week")
def estimated_revenue_this_week():
    HOURLY_RATE = 70
    w = Weekly()
    billable_hours = ms_to_hours(w.billable())
    estimated_revenue = billable_hours * HOURLY_RATE
    content = build_content_for_number_widget(estimated_revenue, 'Estimated revenue this week (GBP)')
    return flask.jsonify(**content)


if __name__ == "__main__":
    app.run(debug=True)
{'fraction_non_alphanumeric': 0.12603305785123967, 'fraction_numerical': 0.012626262626262626, 'mean_word_length': 2.6038047973531846, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '39263', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1410, 'n_words': 286}