Initial commit for Command Line Example

This commit is contained in:
Mathias Köhnke 2016-09-19 23:07:03 +02:00
parent dea2e63dde
commit 4b016c48ee
2 changed files with 56 additions and 2 deletions

View File

@ -2,8 +2,11 @@ import PackageDescription
let package = Package(
name: "WKZombie",
targets: [],
targets: [
Target(name: "WKZombie"),
Target(name: "Example", dependencies:["WKZombie"])
],
dependencies: [
.Package(url: "https://github.com/mkoehnke/hpple.git", Version(0,2,2))
.Package(url: "https://github.com/mkoehnke/hpple.git", Version(0,2,2))
]
)

View File

@ -0,0 +1,51 @@
import Foundation
import WKZombie
let url = URL(string: "https://developer.apple.com/membercenter/index.action")!
let arguments = CommandLine.arguments
let user = arguments[1]
let password = arguments[2]
var shouldKeepRunning = true
func handleResult(_ result: Result<[HTMLTableRow]>) {
shouldKeepRunning = false
switch result {
case .success(let value): handleSuccess(result: value)
case .error(let error): handleError(error: error)
}
}
func handleSuccess(result: [HTMLTableRow]?) {
print("\n")
print("PROVISIONING PROFILES:")
print("======================")
if let columns = result?.flatMap({ $0.columns?.first }) {
for column in columns {
if let element = column.children()?.first as HTMLElement?, let text = element.text {
print(text)
}
}
} else {
print("Nothing found.")
}
}
func handleError(error: ActionError) {
print(error)
}
open(url)
>>> get(by: .id("accountname"))
>>> setAttribute("value", value: user)
>>> get(by: .id("accountpassword"))
>>> setAttribute("value", value: password)
>>> get(by: .name("form2"))
>>> submit(then: .wait(2.0))
>>> get(by: .contains("href", "/account/"))
>>> click(then: .wait(2.5))
>>> getAll(by: .contains("class", "row-"))
=== handleResult
let theRL = RunLoop.current
while shouldKeepRunning && theRL.run(mode: .defaultRunLoopMode, before: .distantFuture) { }