Last active
August 8, 2016 17:36
-
-
Save pinglamb/3cd4a44c10e54a091227f1c52167b212 to your computer and use it in GitHub Desktop.
Soukay.go
This file contains hidden or 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
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") | |
} |
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment