This commit is contained in:
Balakrishnan Balasubramanian 2022-05-03 17:48:42 -04:00
parent 46d173d06c
commit 61c73803c7
16 changed files with 6 additions and 422 deletions

View File

@ -11,13 +11,16 @@
https://gist.github.com/zdebra/10f0e284c4672e99f0cb767298f20c11 https://gist.github.com/zdebra/10f0e284c4672e99f0cb767298f20c11
* ✓ First Run skip all but first n * ✓ First Run skip all but first n
* ✓ Folder creation * ✓ Folder creation
* ✓ Wrap content inside item * ✓ Wrap content inside item ⚠️ atom calls it entry
* ✓ Implement atom
* ✓ Cleanup
* Change flags to os.Args[1] for config path * Change flags to os.Args[1] for config path
* Cleanup
* Make Rhash optional * Make Rhash optional
## Issues ## Issues
* ✓ Last record is not written fully to csv: *Fixed*. Had to Flush writer * ✓ Last record is not written fully to csv: *Fixed*. Had to Flush writer
* Wrap entry content properly
* Some random chars in request/response data
## MVP 2 ## MVP 2
* Podcasts * Podcasts
@ -52,3 +55,4 @@
### Log ### Log
* Log to file * Log to file
* unit testing logs? * unit testing logs?
* Use go-logr Logger interface

View File

@ -1 +0,0 @@
package app

View File

@ -1,20 +0,0 @@
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()))
}

View File

View File

@ -1,41 +0,0 @@
package main
import (
"bytes"
"encoding/csv"
"fmt"
"time"
"gopkg.in/yaml.v3"
)
func main() {
fmt.Println("vim-go")
fb := bytes.NewReader(nil)
cr := csv.NewReader(fb)
records, err := cr.ReadAll()
fmt.Println(records, err)
fmt.Println(time.Now().String())
yesterday := time.Now().Add(-24 * time.Hour)
m := map[string]time.Time{
"Bala": time.Now(),
"Linus": yesterday,
}
data, _ := yaml.Marshal(&m)
fmt.Printf("%s\n", data)
//format := "2022-05-01T15:08:20.593630746-04:00"
format := "2006-01-02T15:04:05.999999999-07:00"
fmt.Println("============")
fmt.Println(yesterday.Format(format))
fmt.Println("============")
fmt.Println(yesterday.GoString())
}
/*
Linus:
============
2022-04-30T15:14:40.302916106-04:00
2022-04-30T15:14:40.302916106-04:00
*/

View File

@ -1,30 +0,0 @@
package main
import (
"bytes"
"encoding/csv"
"fmt"
"io"
)
func main() {
fmt.Println("vim-go")
var b bytes.Buffer
writer := csv.NewWriter(&b)
err := writer.Write([]string{
"foo",
"bar",
"blah",
})
if err != nil {
panic(err)
}
writer.Flush()
b.WriteString("Hello World")
content, err := io.ReadAll(&b)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", content)
fmt.Println("bye")
}

View File

@ -1,19 +0,0 @@
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)
}
}

View File

@ -1,29 +0,0 @@
package main
import (
"fmt"
"log"
"os"
)
func main() {
fmt.Println("vim-go")
f, err := os.Create("./lsdkj/lfksdjf")
if err != nil {
log.Panicln(err)
}
err = f.Close()
if err != nil {
log.Panicln(err)
}
log.Println("created")
/*
data, err := os.ReadFile("./foo/notexist")
if err == nil {
fmt.Println(data)
} else if errors.Is(err, os.ErrNotExist) {
fmt.Printf("not exist: %v\n", err)
}
fmt.Printf("err: %v\n", err)
*/
}

View File

@ -1,35 +0,0 @@
package main
import (
"fmt"
"net"
)
type Foo interface {
Bar()
}
func bar() {
fmt.Println("bar")
}
func run(f Foo) {
f.Bar()
}
type t struct {
Bar func()
}
type t2 struct {
}
func (t t2) Bar() {
bar()
}
func main() {
run(t2{})
var d net.Dialer
d.Cancel
}

View File

@ -1,17 +0,0 @@
package main
import (
"fmt"
"go.balki.me/tss/log"
"go.uber.org/zap"
)
func main() {
fmt.Println("vim-go")
log.Info("does this work", "trycount", 1)
// fmt.Sprint("ldskfjdsice")
s := zap.S()
s.Warnw("How does this look", "trycount", 2)
s.Sync()
}

View File

@ -1,27 +0,0 @@
package main
import (
"fmt"
"io"
"log"
"net/http"
"go.balki.me/tss/proxy"
)
func main() {
trans, err := proxy.GetTransport("socks5://unix/run/tor/socks")
client := &http.Client{
Transport: trans,
}
res, err := client.Get("https://ip.balki.me")
if err != nil {
log.Panicln(err)
}
data, err := io.ReadAll(res.Body)
if err != nil {
log.Panicln(err)
}
fmt.Printf("status: %v, data: %s\n", res.Status, data)
fmt.Printf("%#v\n", client.Transport)
}

View File

@ -1,35 +0,0 @@
package main
import "fmt"
type dummy struct {
name string
}
func main() {
fmt.Println("vim-go")
dummies := []dummy{
dummy{"foo"},
dummy{"bar"},
dummy{"baz"},
}
for i, _ := range dummies {
dum := &dummies[i]
dum.name = "hello"
}
for _, dum := range dummies {
fmt.Println(dum.name)
}
foo()
}
func foo() {
var stuff []string
defer fmt.Println(stuff)
stuff = append(stuff, "foo")
stuff = append(stuff, "bar")
}

View File

@ -1,14 +0,0 @@
package main
import "fmt"
func main() {
var arr []int
for i := 0; i < 10; i++ {
arr = append(arr, i)
}
fmt.Println(arr)
fmt.Println(arr[:0], arr[0:])
fmt.Println(arr[:4], arr[4:])
fmt.Println(arr[:15], arr[15:])
}

View File

@ -1,30 +0,0 @@
package main
import (
"io"
"log"
"net/http"
"net/url"
)
func main() {
//proxyUrl, err := url.Parse("socks5://unix//run/tor/socks")
proxyUrl, err := url.Parse("socks5://127.0.0.1:9050/#Foo")
if err != nil {
log.Panicln(err)
}
log.Println(len(proxyUrl.Path))
client := http.Client{
Transport: &http.Transport{
Proxy: func(*http.Request) (*url.URL, error) { return proxyUrl, nil },
},
}
// res, err := client.Get("http://hz3ppwwc55ccokb63r4ou7za45c5raodu23absuregtqo5ha3h37gfyd.onion")
res, err := client.Get("https://ip.balki.me")
if err != nil {
log.Panicln(err)
}
data, err := io.ReadAll(res.Body)
log.Printf("data: %s, status: %s\n", data, res.Status)
}

View File

@ -1,121 +0,0 @@
package main
import (
"bytes"
"encoding/csv"
"encoding/xml"
"fmt"
"io"
"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")
foo()
if 1 == 1 {
return
}
data, err := os.ReadFile("/home/balki/projects/tss/w.tmp/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)
}
var b bytes.Buffer
b.WriteString("hello world")
csvw := csv.NewWriter(&b)
csvw.Write([]string{
"date",
"link",
"info",
})
for index, item := range v.Items[:3] {
c := item.Content
fmt.Println(index, len(c), item.Title)
//fmt.Println(item.Content)
err = csvw.Write([]string{
time.Now().String(),
item.Link,
strings.Replace(c, "\n", " ", -1),
})
if err != nil {
panic(err)
}
/*
err = csvw.Write([]string{
time.Now().String(),
"dummy.link",
"dummy content, lskdjf lksjdf lkjk",
})
if err != nil {
panic(err)
}
*/
}
csvw.Flush()
err = f.Sync()
fmt.Println(err)
data2, err := io.ReadAll(&b)
fmt.Printf("data2: %s\n", data2)
fmt.Println(err)
// fmt.Println(v.Items[len(v.Items)-1].Content)
}
func foo() {
x := `
<foo>
<bar src="hello">
<link href="http://foobar.com">Hello World</link>
<blue>slkdfjdslk</blue>
</bar>
</foo>
`
s := struct {
Bar struct {
Link struct {
Href string `xml:"href,attr"`
} `xml:"link"`
Attr string `xml:"src,attr"`
Content string `xml:",innerxml"`
} `xml:"bar"`
}{}
err := xml.Unmarshal([]byte(x), &s)
if err != nil {
log.Fatal(err)
}
fmt.Println(s.Bar.Link.Href)
}

View File

@ -1 +0,0 @@
package log