Browse Source

update 0.2.3

master
syui 2 years ago
parent
commit
6dd61c34a7
No known key found for this signature in database GPG Key ID: ED2A0F5F1DA25512
  1. 2
      .travis.yml
  2. 194
      xq.go

2
.travis.yml

@ -14,4 +14,4 @@ before_install:
script:
- gox -output "dist/{{.OS}}_{{.Arch}}_{{.Dir}}"
- ghr --username syui --token $GITHUB_TOKEN --replace --debug 0.2.2 dist/
- ghr --username syui --token $GITHUB_TOKEN --replace --debug 0.2.3 dist/

194
xq.go

@ -1,115 +1,121 @@
package main
import (
"fmt"
"os"
"encoding/json"
"github.com/urfave/cli/v2"
_ "reflect"
gofeed "github.com/mmcdole/gofeed"
"fmt"
"os"
"encoding/json"
"github.com/urfave/cli/v2"
_ "reflect"
gofeed "github.com/mmcdole/gofeed"
)
func App() *cli.App {
app := cli.NewApp()
app.Name = "xq"
app.Usage = "xq a /path/to/rss.xml"
app.Version = "0.2.2"
return app
app := cli.NewApp()
app.Name = "xq"
app.Usage = "xq a /path/to/rss.xml"
app.Version = "0.2.3"
return app
}
type RssItem struct {
Title string `json:"title"`
Link string `json:"link"`
Updated string `json:"update"`
Published string `json:"publish"`
Title string `json:"title"`
Link string `json:"link"`
Updated string `json:"update"`
Published string `json:"publish"`
}
type RssItems []RssItem
func (b RssItems) Len() int {
return len(b)
return len(b)
}
func Action(c *cli.Context) {
app := App()
if c.Args().Get(0) == "" {
help := []string{"", "--help"}
app.Run(help)
os.Exit(1)
}
return
app := App()
if c.Args().Get(0) == "" {
help := []string{"", "--help"}
app.Run(help)
os.Exit(1)
}
return
}
func main() {
app := App()
app.Commands = []*cli.Command{
{
Name: "item",
Aliases: []string{"i"},
Usage: "xq i ./index.xml #output [title,link,update,publish]",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
items := feed.Items
var RssItems RssItems
for _, item := range items {
var RssItem RssItem = RssItem{item.Title, item.Link, item.Updated, item.Published}
RssItems = append(RssItems, RssItem)
}
for _, item := range RssItems {
fmt.Printf("{\"title\":\"%s\",\"link\":\"%s\",\"update\":\"%s\",\"publish\":\"%s\"}\n", item.Title, item.Link, item.Updated, item.Published)
}
return nil
},
},
{
Name: "update",
Aliases: []string{"u","l"},
Usage: "xq u ./index.xml #latest updated",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
fmt.Println(feed.Updated)
return nil
},
},
{
Name: "publish",
Aliases: []string{"p"},
Usage: "xq p ./index.xml #latest items published",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
item := feed.Items[0].Published
fmt.Printf("%s\n",item)
return nil
},
},
{
Name: "all",
Aliases: []string{"a"},
Usage: "xq a ./index.xml #json",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
items := feed.Items
outputJson, err := json.Marshal(&items)
if err != nil {
panic(err)
}
fmt.Printf("%s", string(outputJson))
return nil
},
},
}
app.Run(os.Args)
app := App()
app.Commands = []*cli.Command{
{
Name: "item",
Aliases: []string{"i"},
Usage: "xq i ./index.xml #output [title,link,update,publish]",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
items := feed.Items
var RssItems RssItems
for _, item := range items {
var RssItem RssItem = RssItem{item.Title, item.Link, item.Updated, item.Published}
RssItems = append(RssItems, RssItem)
}
for i, item := range RssItems {
if i == 0 {
fmt.Printf("[")
}
if i == len(items) - 1 {
fmt.Printf("{\"title\":\"%s\",\"link\":\"%s\",\"update\":\"%s\",\"publish\":\"%s\"}]", item.Title, item.Link, item.Updated, item.Published)
} else {
fmt.Printf("{\"title\":\"%s\",\"link\":\"%s\",\"update\":\"%s\",\"publish\":\"%s\"},", item.Title, item.Link, item.Updated, item.Published)
}
}
return nil
},
},
{
Name: "update",
Aliases: []string{"u","l"},
Usage: "xq u ./index.xml #latest updated",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
fmt.Println(feed.Updated)
return nil
},
},
{
Name: "publish",
Aliases: []string{"p"},
Usage: "xq p ./index.xml #latest items published",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
item := feed.Items[0].Published
fmt.Printf("%s\n",item)
return nil
},
},
{
Name: "all",
Aliases: []string{"a"},
Usage: "xq a ./index.xml #json",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
feed, _ := fp.Parse(file)
items := feed.Items
outputJson, err := json.Marshal(&items)
if err != nil {
panic(err)
}
fmt.Printf("%s", string(outputJson))
return nil
},
},
}
app.Run(os.Args)
}

Loading…
Cancel
Save