<commit_before>package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"time"

	"github.com/manifoldco/promptui"
)

func main() {
	fmt.Println("RPNow Admin Console")

	err := checkStatus()
	if err != nil {
		panic(err)
	}
	rps, err := getRpList()
	if err != nil {
		panic(err)
	}

	for {
		rp, err := pickRp(rps)
		if err != nil {
			panic(err)
		}
		urls, err := getRpUrls(rp.RPID)
		if err != nil {
			panic(err)
		}
		fmt.Println(urls)
	}
}

func checkStatus() error {
	fmt.Print("Getting server status... ")

	res, err := http.Get("http://127.0.0.1:12789/status")
	if err != nil {
		return err
	}
	defer res.Body.Close()
	var status struct {
		RPNowLine string `json:"rpnow"`
		PID       int    `json:"pid"`
	}
	err = json.NewDecoder(res.Body).Decode(&status)
	if err != nil {
		return err
	}
	fmt.Println(status.RPNowLine)
	return nil
}

func pickRp(rps []rpInfo) (*rpInfo, error) {
	strings := make([]string, len(rps))
	for i, v := range rps {
		str := v.String()
		strings[i] = str
	}

	prompt := promptui.Select{
		Label: "Choose an RP:",
		Items: strings,
	}

	idx, _, err := prompt.Run()
	if err != nil {
		return nil, err
	}

	return &rps[idx], nil
}

type rpInfo struct {
	Title     string    `json:"title"`
	RPID      string    `json:"rpid"`
	Timestamp time.Time `json:"timestamp"`
}

func (r *rpInfo) String() string {
	return fmt.Sprintf("%-30s (%s)", r.Title, r.Timestamp.Format("02 Jan 2006"))
}

func getRpList() ([]rpInfo, error) {
	res, err := http.Get("http://127.0.0.1:12789/rps")
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	var rps []rpInfo
	err = json.NewDecoder(res.Body).Decode(&rps)
	if err != nil {
		return nil, err
	}
	return rps, nil
}

type rpURL struct {
	URL    string `json:"url"`
	Access string `json:"access"`
}

func getRpUrls(rpid string) ([]rpURL, error) {
	res, err := http.Get(fmt.Sprintf("http://127.0.0.1:12789/rps/%s", rpid))
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	var urls []rpURL
	err = json.NewDecoder(res.Body).Decode(&urls)
	if err != nil {
		return nil, err
	}
	return urls, nil
}
<commit_msg>Details page for an RP<commit_after>package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"time"

	"github.com/manifoldco/promptui"
)

func main() {
	fmt.Println("RPNow Admin Console")

	err := checkStatus()
	if err != nil {
		panic(err)
	}
	rps, err := getRpList()
	if err != nil {
		panic(err)
	}

	for {
		rp, err := pickRp(rps)
		if err != nil {
			panic(err)
		}
		urls, err := getRpUrls(rp.RPID)
		if err != nil {
			panic(err)
		}
		fmt.Println(rp.Title)
		fmt.Printf("Available at %d URLs:\n", len(urls))
		for _, url := range urls {
			fmt.Printf("*  %s\n", url.String())
		}

		for {
			prompt := promptui.Select{
				Label: "Action",
				Items: []string{"go back"},
			}
			_, action, err := prompt.Run()
			if err != nil {
				panic(err)
			}
			if action == "go back" {
				break
			}
		}
	}
}

func checkStatus() error {
	fmt.Print("Getting server status... ")

	res, err := http.Get("http://127.0.0.1:12789/status")
	if err != nil {
		return err
	}
	defer res.Body.Close()
	var status struct {
		RPNowLine string `json:"rpnow"`
		PID       int    `json:"pid"`
	}
	err = json.NewDecoder(res.Body).Decode(&status)
	if err != nil {
		return err
	}
	fmt.Println(status.RPNowLine)
	return nil
}

func pickRp(rps []rpInfo) (*rpInfo, error) {
	strings := make([]string, len(rps))
	for i, v := range rps {
		str := v.String()
		strings[i] = str
	}

	prompt := promptui.Select{
		Label: "Choose an RP",
		Items: strings,
	}
	idx, _, err := prompt.Run()
	if err != nil {
		return nil, err
	}

	return &rps[idx], nil
}

type rpInfo struct {
	Title     string    `json:"title"`
	RPID      string    `json:"rpid"`
	Timestamp time.Time `json:"timestamp"`
}

func (r *rpInfo) String() string {
	return fmt.Sprintf("%-30s (%s)", r.Title, r.Timestamp.Format("02 Jan 2006"))
}

func getRpList() ([]rpInfo, error) {
	res, err := http.Get("http://127.0.0.1:12789/rps")
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	var rps []rpInfo
	err = json.NewDecoder(res.Body).Decode(&rps)
	if err != nil {
		return nil, err
	}
	return rps, nil
}

type rpURL struct {
	URL    string `json:"url"`
	Access string `json:"access"`
}

func (u *rpURL) String() string {
	if u.Access == "normal" {
		return "/rp/" + u.URL
	} else if u.Access == "read" {
		return "/read/" + u.URL
	} else {
		return "???" + u.Access + "???"
	}
}

func getRpUrls(rpid string) ([]rpURL, error) {
	res, err := http.Get("http://127.0.0.1:12789/rps/" + rpid)
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	var urls []rpURL
	err = json.NewDecoder(res.Body).Decode(&urls)
	if err != nil {
		return nil, err
	}
	return urls, nil
}

{'fraction_non_alphanumeric': 0.17911714770797962, 'fraction_numerical': 0.01740237691001698, 'mean_word_length': 3.0594315245478034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '302106', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1909, 'n_words': 471}