Skip to content

Instantly share code, notes, and snippets.

@pinglamb
Last active August 8, 2016 17:36
Show Gist options
  • Select an option

  • Save pinglamb/3cd4a44c10e54a091227f1c52167b212 to your computer and use it in GitHub Desktop.

Select an option

Save pinglamb/3cd4a44c10e54a091227f1c52167b212 to your computer and use it in GitHub Desktop.

Revisions

  1. pinglamb revised this gist Aug 8, 2016. 1 changed file with 71 additions and 0 deletions.
    71 changes: 71 additions & 0 deletions fukong.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    package main

    import (
    "fmt"
    "os"
    "strconv"
    "strings"
    "github.com/PuerkitoBio/goquery"
    )

    func main() {
    if len(os.Args) < 2 {
    printUsage()
    return
    }

    b := os.Args[1]

    bv, err := strconv.ParseFloat(b, 64)
    bv = bv * 10000
    if err != nil {
    printUsage()
    fmt.Println("[buget] needs to be a number")
    return
    }

    fv := 1
    tv := 3000
    var lm int

    for {
    mid := (fv + tv) / 2

    var r string
    var rv float64

    doc, err := goquery.NewDocument(fmt.Sprintf("http://vlshk.com/bc/jason.php?price=%v", mid))
    if err == nil {
    e := doc.Find(".summaryoutput .displaysection .displayrow:nth-child(2) .value")
    r = e.Text()
    if strings.Contains(r, "萬") {
    r = strings.Replace(e.Text(), "萬", "", 1)
    rv, _ = strconv.ParseFloat(r, 64)
    rv = rv * 10000
    } else {
    r = strings.Replace(e.Text(), "$", "", 1)
    rv, _ = strconv.ParseFloat(r, 64)
    }
    }

    if mid == lm {
    fmt.Printf("$%v萬樓 - $%s萬首期\n", mid, r)
    break
    }

    if bv > rv {
    lm = mid
    fv = mid
    } else if bv < rv {
    lm = mid
    tv = mid
    } else {
    fmt.Printf("$%v萬樓 - $%s萬首期\n", mid, r)
    break
    }
    }
    }

    func printUsage() {
    fmt.Println("Usage: ./fukong [budget], e.g. ./fukong 60")
    }
  2. pinglamb created this gist Aug 8, 2016.
    11 changes: 11 additions & 0 deletions soukay.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    require 'httparty'
    require 'nokogiri'

    f, t = (ARGV[0] || 350).to_i, (ARGV[1] || 450).to_i
    f.step(t, 10).each do |v|
    r = HTTParty.get("http://vlshk.com/bc/jason.php?price=#{v}")
    doc = Nokogiri::HTML(r)

    soukay = doc.css('.summaryoutput .displaysection .displayrow:nth-of-type(1) .value').text
    puts "$#{v}萬 - #{soukay}"
    end