<commit_before>package main

import (
	"fmt"
	"github.com/ChimeraCoder/anaconda"
	"net/url"
	"os"
)

type TwitterAccount struct {
	username string
}

type Twitter struct {
	OauthKey     string
	OauthSecret  string
	AccessToken  string
	AccessSecret string
	Client       *anaconda.TwitterApi
}

func BuildTwitter() *Twitter {
	client := &Twitter{
		OauthKey:     os.Getenv("TWITTER_OAUTH_KEY"),
		OauthSecret:  os.Getenv("TWITTER_OAUTH_SECRET"),
		AccessToken:  os.Getenv("TWITTER_ACCESS_TOKEN"),
		AccessSecret: os.Getenv("TWITTER_ACCESS_SECRET"),
	}
	anaconda.SetConsumerKey(client.OauthKey)
	anaconda.SetConsumerSecret(client.OauthSecret)
	client.Client = anaconda.NewTwitterApi(client.AccessToken, client.AccessSecret)

	return client
}

func (t *Twitter) fetchUser(account string, collector *Metrics) {
	user, err := t.Client.GetUsersShow(account, url.Values{})
	if err != nil {
		Log("Couldn't fetch twitter data")
	} else {
		Log("account.data name=%s followers=%d following=%d", user.Name, user.FollowersCount, user.FriendsCount)

		go collector.TrackGauge(fmt.Sprintf("twitter.%s.followers", account), int64(user.FollowersCount))
		go collector.TrackGauge(fmt.Sprintf("twitter.%s.following", account), int64(user.FriendsCount))
	}
}<commit_msg>track the number of mentions in the past 24 hours<commit_after>package main

import (
	"fmt"
	"github.com/ChimeraCoder/anaconda"
	"net/url"
	"os"
  "time"
)

type TwitterAccount struct {
	username string
}

type Twitter struct {
	OauthKey     string
	OauthSecret  string
	AccessToken  string
	AccessSecret string
	Client       *anaconda.TwitterApi
}

func BuildTwitter() *Twitter {
	client := &Twitter{
		OauthKey:     os.Getenv("TWITTER_OAUTH_KEY"),
		OauthSecret:  os.Getenv("TWITTER_OAUTH_SECRET"),
		AccessToken:  os.Getenv("TWITTER_ACCESS_TOKEN"),
		AccessSecret: os.Getenv("TWITTER_ACCESS_SECRET"),
	}
	anaconda.SetConsumerKey(client.OauthKey)
	anaconda.SetConsumerSecret(client.OauthSecret)
	client.Client = anaconda.NewTwitterApi(client.AccessToken, client.AccessSecret)

	return client
}

func (t *Twitter) fetchUser(account string, collector *Metrics) {
	user, err := t.Client.GetUsersShow(account, url.Values{})
	if err != nil {
		Log("Couldn't fetch twitter data")
	} else {
		Log("account.data name=%s followers=%d following=%d", account, user.FollowersCount, user.FriendsCount)

    go collector.TrackGauge(fmt.Sprintf("twitter.%s.followers", account), int64(user.FollowersCount))
    go collector.TrackGauge(fmt.Sprintf("twitter.%s.following", account), int64(user.FriendsCount))
	}

  searchParams, _ := url.ParseQuery("count=100")
  search, err := t.Client.GetSearch(fmt.Sprintf("@%s", account), searchParams)
  if err != nil {
    Log("Couldn't fetch twitter search data")
  } else {
    yesterday := time.Now().Add(-(24 * time.Hour))
    searchCount := 0

    for _, result := range search {
      createdAt, _ := result.CreatedAtTime()
      if createdAt.After(yesterday) {
        searchCount += 1
      }
    }

    Log("account.search name=%s results=%d total=%d", account, searchCount, len(search))
    go collector.TrackGauge(fmt.Sprintf("twitter.%s.mentions", account), int64(searchCount))
  }
}
{'fraction_non_alphanumeric': 0.1307910494799874, 'fraction_numerical': 0.005988023952095809, 'mean_word_length': 4.834558823529412, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4455610', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1073, 'n_words': 210}