Created
January 24, 2019 05:30
-
-
Save palindrom615/2d1025e465ec70c48eb754869113da29 to your computer and use it in GitHub Desktop.
personal go script for extracting urls from evernote scraps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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