Last active
September 15, 2021 00:19
-
-
Save yukirin/bf9ecd131ea37998aa7a to your computer and use it in GitHub Desktop.
https://github.com/yukirin/E2P Evernoteのエクスポートデータ(.enex)をPocketがインポートできる形式へ変換
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" | |
"html/template" | |
"io" | |
"log" | |
"os" | |
) | |
// EnExport is en-export tag | |
type EnExport struct { | |
Note []Note `xml:"note"` | |
} | |
// Note is note tag | |
type Note struct { | |
Title string `xml:"title"` | |
Source string `xml:"note-attributes>source-url"` | |
} | |
func convert(r io.Reader, w io.Writer) error { | |
e := EnExport{} | |
if err := xml.NewDecoder(r).Decode(&e); err != nil { | |
return err | |
} | |
// source-urlが空だとpocketに追加されないため | |
dummy := "https://getpocket.com/" | |
for i, v := range e.Note { | |
if v.Source == "" { | |
e.Note[i].Source = dummy + fmt.Sprint(i) | |
} | |
} | |
t := template.Must(template.New("pocket").Parse(tpl)) | |
if err := t.Execute(w, e); err != nil { | |
return err | |
} | |
return nil | |
} | |
func main() { | |
if len(os.Args) != 3 { | |
log.Fatal("引数が間違っています") | |
} | |
in, err := os.Open(os.Args[1]) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
defer in.Close() | |
out, err := os.Create(os.Args[2]) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
defer out.Close() | |
if err := convert(in, out); err != nil { | |
fmt.Println(err) | |
return | |
} | |
} | |
var tpl = ` | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Instapaper: Export</title> | |
</head> | |
<body> | |
<h1>Unread</h1> | |
<ol> | |
{{range $i, $n := .Note}} | |
<li><a href="{{$n.Source}}">{{$n.Title}}</a></li> | |
{{end}} | |
</ol> | |
</body> | |
</html> | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment