Advertisement
ptrelford

Cleanup BlogEngine Spam

Dec 7th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.73 KB | None | 0 0
  1. #r "System.Xml.dll"
  2. open System.Xml
  3.  
  4. let clean (path:string) =
  5.    let doc = XmlDocument()
  6.    doc.Load(path)
  7.  
  8.    let post = doc.["post"]
  9.    printfn "%s" post.["title"].InnerText
  10.    let comments = post.["comments"]
  11.  
  12.    let approved, unapproved =
  13.       [for comment in comments.ChildNodes -> comment]  
  14.       |> List.partition (fun comment ->
  15.          XmlConvert.ToBoolean(comment.Attributes.["approved"].Value.ToLower())
  16.       )
  17.  
  18.    printfn "Approved %d Spam %d" approved.Length unapproved.Length
  19.  
  20.    for comment in unapproved do
  21.       comments.RemoveChild(comment) |> ignore
  22.  
  23.    doc.Save(path)
  24.  
  25. open System.IO
  26. let files = Directory.EnumerateFiles(@"C:\Phil\posts", "*.xml") |> Seq.toArray
  27. for path in files do clean path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement