Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. open System
  2. open System.IO
  3.  
  4. let writeFile path contents = File.WriteAllLines(path, contents)
  5.  
  6. // [<EntryPoint>]
  7. // let main (param: string[]) =
  8. // printfn "%s" "This script will convert a dirty list of unclaimed Humble Bundle keys into an ordered, cleaned one. Copypaste the content of each page one after the other in a text file, starting from the name of the first game in the page, down to the 'click to redeem' text of the last one. \nWhen you're done, save the file to dirty.txt, placing it in the same directory as this executable. \n the file should look like this: \n\n Rain World \n\n Humble Adult Swim Games Bundle \n\n click to redeem on Steam\n\n etc. \n\n Press enter when the file is ready."
  9.  
  10. // Console.ReadLine ()
  11. let redeemRx = Text.RegularExpressions.Regex "Reveal your (.*) key"
  12.  
  13. let coupleGames theList =
  14. theList
  15. |> Array.choose (fun (i, s) ->
  16. let m = redeemRx.Match s
  17. if m.Success then Some(i, m.Groups.[1].Value)
  18. else None)
  19. |> Array.map (fun (i, s) -> (snd (theList.[i-2])), s)
  20.  
  21. let gameCouples =
  22. File.ReadAllLines (__SOURCE_DIRECTORY__ + @"\dirty.txt")
  23. |> Array.map (fun s -> s.Trim())
  24. |> Array.where (fun (s:String) -> (not <| s.StartsWith("===")) || s <> "")
  25. |> Array.indexed
  26. |> coupleGames
  27. |> Array.sortBy fst //name
  28. |> Array.groupBy snd //platform
  29. |> Array.map (fun (s1, l1) -> s1, Array.map (fst >> (+) "\t") l1 |> Array.toList)
  30. |> Array.sortBy fst //platform
  31. |> Array.toList
  32.  
  33. gameCouples
  34. |> List.collect (fun (s, ls) -> "" :: s :: ls)
  35. |> List.toArray
  36. |> writeFile (__SOURCE_DIRECTORY__ + @"\cleanHumble.txt")
  37.  
  38. //printfn "Conversion complete. The clean file is cleanHumble.txt"
  39. //Console.ReadLine ()
  40. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement