intial state
This commit is contained in:
20
exp/cron/cron.go
Normal file
20
exp/cron/cron.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
|
||||
s, err := cron.ParseStandard("@daily")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(s.Next(time.Now()))
|
||||
}
|
19
exp/exec/exec.go
Normal file
19
exp/exec/exec.go
Normal file
@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
c := exec.Command("./script.sh")
|
||||
op, err := c.Output()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
exitErr := err.(*exec.ExitError)
|
||||
fmt.Printf("hello %s\n", exitErr.Stderr)
|
||||
} else {
|
||||
fmt.Printf("%s", op)
|
||||
}
|
||||
}
|
88
exp/xml/xml.go
Normal file
88
exp/xml/xml.go
Normal file
@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
XMLName xml.Name `xml:"person"`
|
||||
FirstName string `xml:"firstname"`
|
||||
Parents interface{} `xml:"parent"`
|
||||
*/
|
||||
|
||||
type Item struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Author string `xml:"author"`
|
||||
Guid string `xml:"guid"`
|
||||
Description string `xml:"description"`
|
||||
Content string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("hello go")
|
||||
data, err := os.ReadFile("./ounapuu.xml")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
v := struct {
|
||||
Items []Item `xml:"channel>item"`
|
||||
}{}
|
||||
|
||||
err = xml.Unmarshal(data, &v)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := os.OpenFile("./data.csv", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
|
||||
defer f.Close()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
csvw := csv.NewWriter(f)
|
||||
csvw.Write([]string{
|
||||
"date",
|
||||
"link",
|
||||
"info",
|
||||
})
|
||||
|
||||
for index, item := range v.Items {
|
||||
fmt.Println(index, item.Title)
|
||||
//fmt.Println(item.Content)
|
||||
c := item.Content
|
||||
csvw.Write([]string{
|
||||
time.Now().String(),
|
||||
item.Link,
|
||||
strings.Replace(c, "\n", " ", -1),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
func foo() {
|
||||
x := `
|
||||
<foo>
|
||||
<bar><blue>slkdfjdslk</blue></bar>
|
||||
</foo>
|
||||
`
|
||||
s := struct {
|
||||
Bar struct {
|
||||
Content string `xml:",innerxml"`
|
||||
} `xml:"bar"`
|
||||
}{}
|
||||
|
||||
err := xml.Unmarshal([]byte(x), &s)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(s.Bar.Content)
|
||||
}
|
Reference in New Issue
Block a user