<commit_before>package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"

	"gopkg.in/yaml.v2"
)

type Response struct {
	DayEntries []Entry `json:"day_entries"`
}

type Entry struct {
	Hours float64
}

type Config struct {
	Email     string
	Password  string
	Subdomain string
}

var configPath = flag.String("config", "./config.yml", "path to config file")

const harvestUrl = "harvestapp.com/daily"

func createRequest(config *Config) *http.Request {
	url := fmt.Sprintf("https://%s.%s", config.Subdomain, harvestUrl)
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		panic(err)
	}
	req.SetBasicAuth(config.Email, config.Password)
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Accept", "application/json")
	return req
}

func main() {
	flag.Parse()
	f, err := os.Open(*configPath)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	configBytes, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}

	c := Config{}
	err = yaml.Unmarshal(configBytes, &c)
	if err != nil {
		panic(err)
	}

	client := &http.Client{}
	request := createRequest(&c)
	res, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}

	data := Response{}
	err = json.Unmarshal(body, &data)
	if err != nil {
		panic(err)
	}

	entry := data.DayEntries[0]
	fmt.Printf("%1.2f", entry.Hours)
}<commit_msg>Total time by default, new -o gives only current timer<commit_after>package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"

	"gopkg.in/yaml.v2"
)

type response struct {
	DayEntries []entry `json:"day_entries"`
}

type entry struct {
	Hours float64
}

type config struct {
	Email     string
	Password  string
	Subdomain string
}

var configPath = flag.String("config", "./config.yml", "path to config file")
var currentOnly = flag.Bool("o", false, "only show current time")

const harvestURL = "harvestapp.com/daily"

func createRequest(c *config) *http.Request {
	url := fmt.Sprintf("https://%s.%s", c.Subdomain, harvestURL)
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		panic(err)
	}
	req.SetBasicAuth(c.Email, c.Password)
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Accept", "application/json")
	return req
}

func main() {
	flag.Parse()
	f, err := os.Open(*configPath)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	configBytes, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}

	c := config{}
	err = yaml.Unmarshal(configBytes, &c)
	if err != nil {
		panic(err)
	}

	client := &http.Client{}
	request := createRequest(&c)
	res, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}

	data := response{}
	err = json.Unmarshal(body, &data)
	if err != nil {
		panic(err)
	}

	var sum float64
	if *currentOnly {
		entry := data.DayEntries[len(data.DayEntries)-1]
		sum = entry.Hours
	} else {
		for _, entry := range data.DayEntries {
			sum += entry.Hours
		}
	}
	fmt.Printf("%1.2f", sum)
}
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.004478566858605247, 'mean_word_length': 3.73071104387292, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5148191', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1201, 'n_words': 285}