-
-
Save callmekohei/f92021082dd1ffcdf8e76e40befb8f3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "./packages/FSharp.Data/lib/net40/FSharp.Data.dll" | |
open FSharp.Data | |
open System.Text | |
module Util = | |
let Justify lst = | |
let swapRowColumn lst = | |
lst | |
|> List.collect List.indexed | |
|> List.groupBy fst | |
|> List.map snd | |
|> List.map (List.map snd) | |
let sjis = Encoding.GetEncoding "Shift_JIS" | |
let justify lst = | |
let lst = List.map (fun (str : string) -> str, sjis.GetByteCount str) lst | |
let max = | |
lst | |
|> List.map snd | |
|> List.max | |
List.map (fun (str, len) -> str + String.replicate (max - len) " ") lst | |
lst | |
|> swapRowColumn | |
|> List.map justify | |
|> swapRowColumn | |
module Main = | |
let url = @"http://www.traders.co.jp/fx/fx_schedule_con.asp" | |
Http.RequestString( url , responseEncodingOverride = "shift-JIS") | |
|> HtmlDocument.Parse | |
|> fun doc -> | |
let update = doc.CssSelect(@".updatetime") |> List.map(fun n -> n.InnerText()) | |
stdout.WriteLine("===== Traders Web ( " + update.[0] + " ) =====") | |
let l = doc.CssSelect( @".scheduletable > tr > td.#" ) | |
|> List.map ( fun n -> n.InnerText() ) | |
|> List.chunkBySize 2 | |
let index = doc.CssSelect( @"table.scheduletable > tr > td.index" ) | |
|> List.map ( fun n -> n.InnerText() ) | |
(l,index) ||> List.map2( fun a b -> a @ [b] ) | |
|> Util.Justify | |
|> List.map (fun l -> List.reduce( fun a b -> a + "\t" + b) l ) | |
|> List.iter stdout.WriteLine | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment