2017-10-05 22:28:39 +02:00
|
|
|
//
|
|
|
|
// OPMLImporter.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 10/5/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RSParser
|
|
|
|
import Account
|
|
|
|
|
|
|
|
struct OPMLImporter {
|
|
|
|
|
|
|
|
static func parseAndImport(fileURL: URL, account: Account) throws {
|
|
|
|
|
|
|
|
var fileData: Data?
|
|
|
|
|
|
|
|
do {
|
|
|
|
fileData = try Data(contentsOf: fileURL)
|
|
|
|
} catch {
|
|
|
|
print("Error reading OPML file. \(error)")
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let opmlData = fileData else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let parserData = ParserData(url: fileURL.absoluteString, data: opmlData)
|
|
|
|
var opmlDocument: RSOPMLDocument?
|
|
|
|
|
|
|
|
do {
|
|
|
|
opmlDocument = try RSOPMLParser.parseOPML(with: parserData)
|
|
|
|
} catch {
|
|
|
|
print("Error parsing OPML file. \(error)")
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
|
|
|
|
if let opmlDocument = opmlDocument {
|
2017-10-06 05:38:54 +02:00
|
|
|
BatchUpdate.shared.perform {
|
2017-10-06 05:34:29 +02:00
|
|
|
account.importOPML(opmlDocument)
|
|
|
|
}
|
2017-10-05 22:28:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|