Skip to content

Instantly share code, notes, and snippets.

@palindrom615
Created January 24, 2019 05:30
Show Gist options
  • Save palindrom615/2d1025e465ec70c48eb754869113da29 to your computer and use it in GitHub Desktop.
Save palindrom615/2d1025e465ec70c48eb754869113da29 to your computer and use it in GitHub Desktop.
personal go script for extracting urls from evernote scraps
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
file := os.Args[1]
bytes, err := ioutil.ReadFile(file)
if err == nil {}
r := strings.NewReader(string(bytes))
parser := xml.NewDecoder(r)
for {
token, err := parser.Token()
if err != nil {
break
}
elem, ok := token.(xml.StartElement)
if ok && elem.Name.Local == "note-attributes" {
for {
chldElem, _ := parser.Token()
chldElemC, ok := chldElem.(xml.StartElement)
if ok && chldElemC.Name.Local == "source-url" {
content, err := parser.Token()
if err == nil { fmt.Println(string(content.(xml.CharData)[:])) }
break
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment