LoginSignup
2
1

More than 5 years have passed since last update.

[macOS]Day One Classic 書類

Posted at

Day One Classicという日記アプリを使っているが、今後のことを考えて、自家製アプリに移行することを考えている。

Day Oneの同期データの種類は、以下のとおり。

  • Day One
    独自サーバ。
  • iCloud
    
 探せばデータを見つけることは出来るが、見えないと考えるべきか。
    
 ~/Library/Mobile Documents/*~com~dayoneapp~dayone/Documents/Journal_dayone
  • Dropbox
    
 データは見える場所。
    
 ~/Dropbox/アプリ/Day\ One/Journal.dayone

Dropboxでのディレクトリ構成は以下のとおり

Day One
 +- Journal.dayone
    +- entries
    |    1A573C0B559248A991C4AC0F0EA8B1E7.doentry
    |    1FB23D983DF341079532B0F9381BCFCC.doentry
    |    :
    +- photos
         1A573C0B559248A991C4AC0F0EA8B1E7.jpg
         2D37E853754E43EFBA0FFBAEEB6A8B40.jpg
         :

entries配下のファイルは、plistのよう。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Activity</key>
    <string>Automotive</string>
    <key>Creation Date</key>
    <date>2016-07-18T08:51:34Z</date>
    <key>Creator</key>
    <dict>
        <key>Device Agent</key>
        <string>iPhone/iPhone7,2</string>
        <key>Generation Date</key>
        <date>2016-07-18T08:51:34Z</date>
        <key>Host Name</key>
        <string>iPhone6GB128Gold</string>
        <key>OS Agent</key>
        <string>iOS/9.3.2</string>
        <key>Software Agent</key>
        <string>Day One iOS/1.17.9</string>
    </dict>
    <key>Entry Text</key>
    <string>AT教習のゼッケン
下で待つ。準備なし</string>
:

この内容を読み取るコードを書いてみた。保存先を選択する。

    @IBAction func buttonPushed(sender: AnyObject) {
        let openPanel = NSOpenPanel()
        openPanel.allowsMultipleSelection = false
        openPanel.canChooseDirectories = true
        openPanel.canCreateDirectories = false
        openPanel.canChooseFiles = false
        openPanel.begin { (result) -> Void in
            if result == NSFileHandlingPanelOKButton {
                let inst = KeepADiary()
                inst.dump(url: openPanel.urls[0])
            }
        }
    }

内容をダンプ。

class KeepADiary {
    public func dump(url: URL) -> Void {
        print(url)
        var entriesUrl = url
        entriesUrl.appendPathComponent("entries", isDirectory: true)
        print(entriesUrl)
        var fileList: [String] {
            do {
                return try FileManager.default.contentsOfDirectory(atPath: entriesUrl.path)
            } catch {
                return []
            }
        }
        for fileName in fileList {
            var fileUrl = entriesUrl
            fileUrl.appendPathComponent(fileName)
            let plistXML: NSData = FileManager.default.contents(atPath: fileUrl.path)! as NSData
            let temp = try! PropertyListSerialization.propertyList(from:plistXML as Data, options: [], format: nil) as! [String:Any]
            print(temp)
        }
    }
}

ソースコード
GitHubからどうぞ。

https://github.com/murakami/KeepADiary - GitHub

関連情報
Cocoa勉強会 BUKURO.swift (connpass)

Swift勉強会 関東 (connpass)

Cocoa勉強会 BUKURO.swift (ATND)

Cocoa勉強会 BUKURO.swift (Peatix)

MOSA BUKURO.swift (connpass)

【Cocoa練習帳】
http://www.bitz.co.jp/weblog/

http://ameblo.jp/bitz/(ミラー・サイト)

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1