<commit_before>// -*- tab-width: 4; -*-

package main

import (
	"errors"
	"flag"
	"fmt"
	"os"
	"regexp"
	"sort"
	"strings"
	"time"

	"gopkg.in/readline.v1"
)

func timeline_command(args []string) error {
	fs := flag.NewFlagSet("timeline", flag.ExitOnError)
	durationFlag := fs.Duration("d", 0, "only show tweets created at most `duration` back in time. Example: -d 12h")
	sourceFlag := fs.String("s", "", "only show timeline for given nick")
	fs.Usage = func() {
		fmt.Printf("usage: %s timeline [arguments]\n\nDisplays the timeline.\n\n", progname)
		fs.PrintDefaults()
	}
	fs.Parse(args) // currently using flag.ExitOnError, so we won't get an error on -h
	if fs.NArg() > 0 {
		return errors.New("too many arguments given")
	}
	if *durationFlag < 0 {
		return errors.New("negative duration doesn't make sense")
	}

	var sources map[string]string = conf.Following
	if *sourceFlag != "" {
		url, ok := conf.Following[*sourceFlag]
		if !ok {
			return errors.New(fmt.Sprintf("no source with nick %q", *sourceFlag))
		}
		sources = make(map[string]string)
		sources[*sourceFlag] = url
	}

	cache := Loadcache(configpath)

	alltweets := get_tweets(cache, sources)
	sort.Sort(alltweets)
	now := time.Now().Round(time.Second)
	for _, tweet := range alltweets {
		if *durationFlag == 0 || (now.Sub(tweet.Created)) <= *durationFlag {
			print_tweet(tweet, now)
			fmt.Println()
		}
	}

	cache.Store(configpath)

	return nil
}

func tweet_command(args []string) error {
	fs := flag.NewFlagSet("tweet", flag.ExitOnError)
	fs.Usage = func() {
		fmt.Printf(`usage: %s tweet [words]
   or: %s twet [words]

Adds a new tweet to your twtfile. Words are joined together with a single
space. If no words are given, user will be prompted to input the text
interactively.
`, progname, progname)
		fs.PrintDefaults()
	}
	fs.Parse(args) // currently using flag.ExitOnError, so we won't get an error on -h

	twtfile := conf.Twtfile
	if len(twtfile) == 0 {
		return errors.New("cannot tweet without twtfile set in config")
	}
	// We don't support shell style ~user/foo.txt :P
	if strings.HasPrefix(twtfile, "~/") {<commit_msg>Store cache right after refreshing it<commit_after>// -*- tab-width: 4; -*-

package main

import (
	"errors"
	"flag"
	"fmt"
	"os"
	"regexp"
	"sort"
	"strings"
	"time"

	"gopkg.in/readline.v1"
)

func timeline_command(args []string) error {
	fs := flag.NewFlagSet("timeline", flag.ExitOnError)
	durationFlag := fs.Duration("d", 0, "only show tweets created at most `duration` back in time. Example: -d 12h")
	sourceFlag := fs.String("s", "", "only show timeline for given nick")
	fs.Usage = func() {
		fmt.Printf("usage: %s timeline [arguments]\n\nDisplays the timeline.\n\n", progname)
		fs.PrintDefaults()
	}
	fs.Parse(args) // currently using flag.ExitOnError, so we won't get an error on -h
	if fs.NArg() > 0 {
		return errors.New("too many arguments given")
	}
	if *durationFlag < 0 {
		return errors.New("negative duration doesn't make sense")
	}

	var sources map[string]string = conf.Following
	if *sourceFlag != "" {
		url, ok := conf.Following[*sourceFlag]
		if !ok {
			return errors.New(fmt.Sprintf("no source with nick %q", *sourceFlag))
		}
		sources = make(map[string]string)
		sources[*sourceFlag] = url
	}

	cache := Loadcache(configpath)

	alltweets := get_tweets(cache, sources)

	cache.Store(configpath)

	sort.Sort(alltweets)
	now := time.Now().Round(time.Second)
	for _, tweet := range alltweets {
		if *durationFlag == 0 || (now.Sub(tweet.Created)) <= *durationFlag {
			print_tweet(tweet, now)
			fmt.Println()
		}
	}

	return nil
}

func tweet_command(args []string) error {
	fs := flag.NewFlagSet("tweet", flag.ExitOnError)
	fs.Usage = func() {
		fmt.Printf(`usage: %s tweet [words]
   or: %s twet [words]

Adds a new tweet to your twtfile. Words are joined together with a single
space. If no words are given, user will be prompted to input the text
interactively.
`, progname, progname)
		fs.PrintDefaults()
	}
	fs.Parse(args) // currently using flag.ExitOnError, so we won't get an error on -h

	twtfile := conf.Twtfile
	if len(twtfile) == 0 {
		return errors.New("cannot tweet without twtfile set in config")
	}
	// We don't support shell style ~user/foo.txt :P
	if strings.HasPrefix(twtfile, "~/") {
{'fraction_non_alphanumeric': 0.14545454545454545, 'fraction_numerical': 0.004250295159386069, 'mean_word_length': 3.9543859649122806, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '444248', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1493, 'n_words': 431}