Skip to content

Instantly share code, notes, and snippets.

@callmekohei
Last active August 28, 2017 06:54
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 callmekohei/f92021082dd1ffcdf8e76e40befb8f3c to your computer and use it in GitHub Desktop.
Save callmekohei/f92021082dd1ffcdf8e76e40befb8f3c to your computer and use it in GitHub Desktop.
#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