Skip to content

Instantly share code, notes, and snippets.

@imonyse
Created September 20, 2011 03:30
Show Gist options
  • Save imonyse/1228249 to your computer and use it in GitHub Desktop.
Save imonyse/1228249 to your computer and use it in GitHub Desktop.
通过链接,获取tom围棋sgf棋谱,并转换为utf-8编码的脚本
$ ruby get_tom_sgf.rb http://weiqi.sports.tom.com/qipu/201108/16sx-b3-0826-sllch.sgf > utf-8.sgf
#!/usr/bin/env ruby
# Filename: get_tom_sgf.rb
# A very simple script to get tom weiqi's sgf text
# Usage: ruby get_tom_sgf.rb <sgf_file_path>
require 'net/http'
def usage
puts 'usage: ruby get_tom_sgf.rb <sgf_file_path>'
exit!
end
if ARGV.length != 1
usage
end
link = ARGV[0]
sgf = nil
sgf_host = 'weiqi.sports.tom.com'
sgf_path = link[(link.index(sgf_host) + sgf_host.length)..-1]
Net::HTTP.start(sgf_host) do |http|
response = http.get(sgf_path)
sgf = response.body
end
puts sgf.force_encoding('GB18030').encode('UTF-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment