Merge pull request #3 from zetamatta/master
New option: -ff FILENAME: post utf8 string from a file("-" means STDIN)
This commit is contained in:
commit
f4a4a21710
|
@ -24,8 +24,17 @@ import (
|
||||||
var (
|
var (
|
||||||
toot = flag.String("t", "", "toot text")
|
toot = flag.String("t", "", "toot text")
|
||||||
stream = flag.Bool("S", false, "streaming public")
|
stream = flag.Bool("S", false, "streaming public")
|
||||||
|
fromfile = flag.String("ff", "", "post utf-8 string from a file(\"-\" means STDIN)")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func readFile(filename string) ([]byte, error) {
|
||||||
|
if filename == "-" {
|
||||||
|
return ioutil.ReadAll(os.Stdin)
|
||||||
|
} else {
|
||||||
|
return ioutil.ReadFile(filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func extractText(node *html.Node, w *bytes.Buffer) {
|
func extractText(node *html.Node, w *bytes.Buffer) {
|
||||||
if node.Type == html.TextNode {
|
if node.Type == html.TextNode {
|
||||||
data := strings.Trim(node.Data, "\r\n")
|
data := strings.Trim(node.Data, "\r\n")
|
||||||
|
@ -132,6 +141,19 @@ func main() {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if *fromfile != "" {
|
||||||
|
text, err := readFile(*fromfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = client.PostStatus(&mastodon.Toot{
|
||||||
|
Status: string(text),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if *toot != "" {
|
if *toot != "" {
|
||||||
_, err = client.PostStatus(&mastodon.Toot{
|
_, err = client.PostStatus(&mastodon.Toot{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user