Skip to content

Instantly share code, notes, and snippets.

@vpatryshev
Last active December 21, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpatryshev/6336248 to your computer and use it in GitHub Desktop.
Save vpatryshev/6336248 to your computer and use it in GitHub Desktop.
sample code for html data extraction
// we already have a bunch of patient properties on one tab (in props1); now get another bunch from another tab
// we click it and wait for the element to show up; then:
val props2 = extractProperties("div#ctl00_ContentPlaceHolder1_Details_Container2") map (_.trimPrefixes)
// trimming prefixes means we do not care about all the additional keys, but just a variety of values
// now let's blend the two sets together; <*> will produce either Good((p1,p2)) or Bad(errors1 ++ errors2)
val propsOpt: Result[(Props, Props)] = props1 <*> props2
// then we want to merge together two sets of patient properties; that's what we do in map
val patientData = propsOpt map ((xy:(Props, Props)) => (xy._1 ++ xy._2))
debug(s"Got patient data\n $patientData")
// and now we process the resulting patient properties: if the result was good, we push it on stack (we have Forth)
// if the result was bad, we return an error.
// implicits will convert Void to OperationResult.Success and error returns OperationResult.Error
patientData.fold(
push, // this is where my little embedded Forth suddenly kicks in
bad => error(s"Failed to extract data for this patient - $bad")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment