<commit_before>package common

import (
	"fmt"
	"log"
	"strconv"
	"time"
)

// GitHubAPIKeyModel is a struct representing on individual github key in the database
type GitHubAPIKeyModel struct {
	Key                string
	RemainingUses      int
	RequestsPerHour    int
	RateLimitResetTime time.Time
}

// Should pass the number of remaining here instead of -1
// Pass remaining
func (apiKey *GitHubAPIKeyModel) incrementUsage(remainingRequests string, rateLimitResetTime string) {
	n, _ := strconv.ParseInt(rateLimitResetTime, 0, 64)
	resetTime := time.Unix(n, 0)
	l, _ := strconv.Atoi(remainingRequests)
	log.Println("Remaining uses in save ", l)
	apiKey.RemainingUses = l
	apiKey.RateLimitResetTime = resetTime
}

func (apiKey *GitHubAPIKeyModel) reset() {
	apiKey.RemainingUses = 5000
}

func (apiKey *GitHubAPIKeyModel) print() {
	fmt.Printf("%+v", apiKey)
}<commit_msg>add sleep logic in the key model<commit_after>package common

import (
	"fmt"
	"log"
	"net/http"
	"strconv"
	"time"
)

var gitHubAPIBaseUrl = "https://api.github.com/"

// GitHubAPIKeyModel is a struct representing on individual github key in the database
type GitHubAPIKeyModel struct {
	Key                string
	RemainingUses      int
	RequestsPerHour    int
	RateLimitResetTime time.Time
}

// Should pass the number of remaining here instead of -1
// Pass remaining
func (apiKey *GitHubAPIKeyModel) incrementUsage(remainingRequests string, rateLimitResetTime string) {
	n, _ := strconv.ParseInt(rateLimitResetTime, 0, 64)
	resetTime := time.Unix(n, 0)
	l, _ := strconv.Atoi(remainingRequests)
	log.Println("Remaining uses in save ", l)
	apiKey.RemainingUses = l
	apiKey.RateLimitResetTime = resetTime
}

// TODO sent request to api route thats passed in
// TODO should return error
func (apiKey *GitHubAPIKeyModel) prime() {
	githubURL := gitHubAPIBaseUrl + "repos/a/b" + "?access_token=" + apiKey.Key
	log.Println(githubURL)
	resp, err := http.Get(githubURL)
	if err != nil {
	}
	defer resp.Body.Close()
	responseHeader := resp.Header
	remaingRequests := responseHeader.Get("X-RateLimit-Remaining")
	rateLimitResetTime := responseHeader.Get("X-RateLimit-Reset")
	apiKey.incrementUsage(remaingRequests, rateLimitResetTime)
}

func (apiKey *GitHubAPIKeyModel) reset() {
	apiKey.RemainingUses = 5000
}

func (apiKey *GitHubAPIKeyModel) print() {
	fmt.Printf("%+v", apiKey)
}
{'fraction_non_alphanumeric': 0.10582235444113897, 'fraction_numerical': 0.00764980875478113, 'mean_word_length': 4.55188679245283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '7295139', 'n_tokens_mistral': 819, 'n_tokens_neox': 797, 'n_words': 207}