Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open System.IO
- let writeFile path contents = File.WriteAllLines(path, contents)
- // [<EntryPoint>]
- // let main (param: string[]) =
- // 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."
- // Console.ReadLine ()
- let redeemRx = Text.RegularExpressions.Regex "Reveal your (.*) key"
- let coupleGames theList =
- theList
- |> Array.choose (fun (i, s) ->
- let m = redeemRx.Match s
- if m.Success then Some(i, m.Groups.[1].Value)
- else None)
- |> Array.map (fun (i, s) -> (snd (theList.[i-2])), s)
- let gameCouples =
- File.ReadAllLines (__SOURCE_DIRECTORY__ + @"\dirty.txt")
- |> Array.map (fun s -> s.Trim())
- |> Array.where (fun (s:String) -> (not <| s.StartsWith("===")) || s <> "")
- |> Array.indexed
- |> coupleGames
- |> Array.sortBy fst //name
- |> Array.groupBy snd //platform
- |> Array.map (fun (s1, l1) -> s1, Array.map (fst >> (+) "\t") l1 |> Array.toList)
- |> Array.sortBy fst //platform
- |> Array.toList
- gameCouples
- |> List.collect (fun (s, ls) -> "" :: s :: ls)
- |> List.toArray
- |> writeFile (__SOURCE_DIRECTORY__ + @"\cleanHumble.txt")
- //printfn "Conversion complete. The clean file is cleanHumble.txt"
- //Console.ReadLine ()
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement