commit 3dbbd55c0d05efc72caeed8c9e44e09f4f0a03e2
parent 4f9ed4e252bdc1f97ca5c50a735c52dc75b6c6a6
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Fri, 5 Feb 2021 12:36:17 +0300
sort command
Diffstat:
2 files changed, 37 insertions(+), 40 deletions(-)
diff --git a/README.md b/README.md
@@ -86,6 +86,9 @@ slice is the start:limit. For example:
Options are:
```
+-from <user> -- from user
+-to <user> -- to user
+-t -- only topics (w/o repto)
-db <database> -- db by default (db.idx - genetated index)
-v -- show message text, not only MsgId
```
@@ -108,10 +111,12 @@ Where options are:
-db <database> -- db by default (db.idx - genetated index)
-v -- show message text, not only MsgId
```
-To show messages adressed to selected user, try:
+You can sort ids by date with sort command.
+
+To show last 5 messages adressed to selected user, try:
```
-./ii-tool [options] cc <user> [slice]
+./ii-tool [options] -to <user> select "" | ./ii-tool sort | tail -n5 | ./ii-tool -v sort
```
For example:
diff --git a/ii-tool/main.go b/ii-tool/main.go
@@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"os"
+ "sort"
"strings"
)
@@ -60,7 +61,8 @@ func main() {
users_opt := flag.String("u", "points.txt", "Users database")
conns_opt := flag.Int("j", 6, "Maximum parallel jobs")
topics_opt := flag.Bool("t", false, "Select topics only")
-
+ from_opt := flag.String("from", "", "Select from")
+ to_opt := flag.String("to", "", "Select to")
flag.Parse()
ii.MaxConnections = *conns_opt
if *verbose_opt {
@@ -77,9 +79,7 @@ Commands:
fetch <url> [echofile|-] - fetch
store <bundle|-> - import bundle to database
get <msgid> - show message from database
- select <echo> [[start]:lim] - get slice from echo
- cc <name> [[start]:lim] - get msgs to name
- from <name> [[start]:lim] - get msg from name
+ select [[start]:lim] - get slice from echo
index - recreate index
blacklist <msgid> - blacklist msg
useradd <name> <e-mail> <password> - adduser
@@ -88,6 +88,9 @@ Options:
-lim=<lim> - fetch lim last messages
-u=<path> - points account file
-t - topics only (select,get)
+ -from=<user> - select from
+ -to=<user> - select to
+ -echo=echo - select echo
`, os.Args[0])
os.Exit(1)
}
@@ -359,13 +362,20 @@ Options:
if m != nil {
fmt.Println(m)
}
- case "from":
+ case "select":
if len(args) < 2 {
fmt.Printf("No echo supplied\n")
os.Exit(1)
}
db := open_db(*db_opt)
- req := ii.Query{From: args[1]}
+ req := ii.Query{ Echo: args[1] }
+ if *from_opt != "" {
+ req.From = *from_opt
+ }
+ if *to_opt != "" {
+ req.To = *to_opt
+ }
+
if *topics_opt {
req.Repto = "!"
}
@@ -380,43 +390,25 @@ Options:
fmt.Println(v)
}
}
- case "cc":
- if len(args) < 2 {
- fmt.Printf("No echo supplied\n")
- os.Exit(1)
- }
+ case "sort":
db := open_db(*db_opt)
- req := ii.Query{To: args[1]}
- if len(args) > 2 {
- fmt.Sscanf(args[2], "%d:%d", &req.Start, &req.Lim)
- }
- resp := db.SelectIDS(req)
- for _, v := range resp {
- if *verbose_opt {
- fmt.Println(db.Get(v))
- } else {
- fmt.Println(v)
+ db.LoadIndex()
+ scanner := bufio.NewScanner(os.Stdin)
+ var mm []*ii.Msg
+ for scanner.Scan() {
+ mi := db.LookupFast(scanner.Text(), false)
+ if mi != nil {
+ mm = append(mm, db.Get(mi.Id))
}
}
- case "select":
- if len(args) < 2 {
- fmt.Printf("No echo supplied\n")
- os.Exit(1)
- }
- db := open_db(*db_opt)
- req := ii.Query{Echo: args[1]}
- if *topics_opt {
- req.Repto = "!"
- }
- if len(args) > 2 {
- fmt.Sscanf(args[2], "%d:%d", &req.Start, &req.Lim)
- }
- resp := db.SelectIDS(req)
- for _, v := range resp {
+ sort.SliceStable(mm, func(i, j int) bool {
+ return mm[i].Date < mm[j].Date
+ })
+ for _, v := range mm {
if *verbose_opt {
- fmt.Println(db.Get(v))
- } else {
fmt.Println(v)
+ } else {
+ fmt.Println(v.MsgId)
}
}
case "index":