aboutsummaryrefslogtreecommitdiffstats
path: root/skate/cmd/skate-dot/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'skate/cmd/skate-dot/main.go')
-rw-r--r--skate/cmd/skate-dot/main.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/skate/cmd/skate-dot/main.go b/skate/cmd/skate-dot/main.go
new file mode 100644
index 0000000..97b70ad
--- /dev/null
+++ b/skate/cmd/skate-dot/main.go
@@ -0,0 +1,80 @@
+// skate-dot generates dot files from inbound and outbound citation links.
+package main
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "io"
+ "log"
+ "os"
+
+ "github.com/elastic/go-elasticsearch/esapi"
+ elasticsearch "github.com/elastic/go-elasticsearch/v7"
+)
+
+var (
+ es = flag.String("es", "http://localhost:9200", "elasticsearch holding fatcat_ref index")
+ index = flag.String("x", "fatcat_ref_v01", "index name")
+ fatcat = flag.String("f", "https://api.fatcat.wiki/v0", "fatcat api")
+ ident = flag.String("i", "2kw3xjf2cbcmdlm3ihkoz2t4lu", "release ident")
+)
+
+func main() {
+ flag.Parse()
+ // s := "The Determination of Concentration and Type of Ownership on Bank Performance and Risks in Indonesia"
+ // fmt.Printf("%s\n", wordwrap.WrapString(s, 20))
+ cfg := elasticsearch.Config{
+ Addresses: []string{
+ *es,
+ },
+ }
+ es, err := elasticsearch.NewClient(cfg)
+ if err != nil {
+ log.Fatal(err)
+ }
+ client := &Client{
+ Api: *fatcat,
+ Es: es,
+ Index: *index,
+ }
+ log.Println(client)
+ client.Outbound(*ident)
+ client.Inbound(*ident)
+}
+
+// A client for fatcat and elasticsearch.
+type Client struct {
+ Api string
+ Es *elasticsearch.Client
+ Index string
+}
+
+func (c *Client) String() string {
+ info, _ := c.Es.Info()
+ return fmt.Sprintf("%s %s (%s) %s", c.Api, info, elasticsearch.Version, c.Index)
+}
+
+func (c *Client) Inbound(ident string) []string {
+ resp, err := esapi.Search(
+ esapi.Search.WithContext(context.Background()),
+ esapi.Search.WithIndex(c.Index),
+ )
+ if err != nil {
+ log.Fatal(err)
+ }
+ io.Copy(os.Stdout, resp.Body)
+ return nil
+}
+
+func (c *Client) Outbound(ident string) []string {
+ req := &esapi.SearchRequest{
+ Query: fmt.Sprintf("source_release_ident:%s", ident),
+ }
+ resp, err := req.Do(context.Background(), c.Es)
+ if err != nil {
+ log.Fatal(err)
+ }
+ io.Copy(os.Stdout, resp.Body)
+ return nil
+}