Skip to content

Instantly share code, notes, and snippets.

@callmekohei
Created August 29, 2017 06:17
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/836bbad778a3c746e3f9ffa4ad9c4f72 to your computer and use it in GitHub Desktop.
Save callmekohei/836bbad778a3c746e3f9ffa4ad9c4f72 to your computer and use it in GitHub Desktop.
#r "./packages/FSharp.Data/lib/net40/FSharp.Data.dll"
open FSharp.Data
open System.Text
open System.Text.RegularExpressions
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.traderswebfx.jp/marketorder"
Http.RequestString( url , responseEncodingOverride = "UTF-8")
|> HtmlDocument.Parse
|> fun doc ->
stdout.WriteLine("===== Traders Web =====\n")
let update = doc.CssSelect(@".update") |> List.map(fun n -> n.InnerText())
let price = doc.CssSelect( @"table.orderdata > tr > th") |> List.map ( fun n -> n.InnerText() )
let comment = doc.CssSelect( @"table.orderdata > tr > td") |> List.map ( fun n -> n.InnerText() )
let nth = price |> List.findIndex( fun s -> Regex.IsMatch(s,"^\d\.") )
let USDJPY, EURUSD = (price,comment) ||> List.map2 ( fun a b -> a + "\t\t" + b ) |> List.splitAt nth
stdout.WriteLine("----- USDJPY (" + update.[0] + ") -----")
USDJPY |> List.iter stdout.WriteLine
stdout.WriteLine("\n----- EURUSD (" + update.[1] + ") -----")
EURUSD |> List.iter stdout.WriteLine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment