Add xsearch
This commit is contained in:
parent
759ce4a331
commit
e5d11f63aa
|
@ -1,26 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func cmdMikami(c *cli.Context) error {
|
||||
doc, err := goquery.NewDocument("http://mastodonsearch.jp/cross/?q=三上")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
doc.Find(".post").Each(func(n int, elem *goquery.Selection) {
|
||||
href, ok := elem.Find(".mst_content a").Attr("href")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
text := elem.Find(".mst_content p").Text()
|
||||
fmt.Println(href)
|
||||
fmt.Println(text)
|
||||
fmt.Println()
|
||||
})
|
||||
return nil
|
||||
return xsearch(c.App.Metadata["xsearch_url"].(string), "三上", c.App.Writer)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -9,12 +10,16 @@ import (
|
|||
)
|
||||
|
||||
func cmdXSearch(c *cli.Context) error {
|
||||
u, err := url.Parse("http://mastodonsearch.jp/cross/")
|
||||
return xsearch(c.App.Metadata["xsearch_url"].(string), c.Args().First(), c.App.Writer)
|
||||
}
|
||||
|
||||
func xsearch(xsearchRawurl, query string, w io.Writer) error {
|
||||
u, err := url.Parse(xsearchRawurl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params := url.Values{}
|
||||
params.Set("q", c.Args().First())
|
||||
params.Set("q", query)
|
||||
u.RawQuery = params.Encode()
|
||||
doc, err := goquery.NewDocument(u.String())
|
||||
if err != nil {
|
||||
|
@ -26,9 +31,8 @@ func cmdXSearch(c *cli.Context) error {
|
|||
return
|
||||
}
|
||||
text := elem.Find(".mst_content p").Text()
|
||||
fmt.Println(href)
|
||||
fmt.Println(text)
|
||||
fmt.Println()
|
||||
fmt.Fprintf(w, "%s\n", href)
|
||||
fmt.Fprintf(w, "%s\n\n", text)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -361,8 +361,9 @@ func run() int {
|
|||
|
||||
client := mastodon.NewClient(config)
|
||||
app.Metadata = map[string]interface{}{
|
||||
"client": client,
|
||||
"config": config,
|
||||
"client": client,
|
||||
"config": config,
|
||||
"xsearch_url": "http://mastodonsearch.jp/cross/",
|
||||
}
|
||||
if config.AccessToken == "" {
|
||||
return authenticate(client, config, file)
|
||||
|
|
Loading…
Reference in New Issue
Block a user