<commit_before>#!/usr/bin/env ruby

require "httpclient"
require "json"
require "digest"

require_relative "myfunc"
require_relative "config"
require_relative "mylogger"

####################################
# btc38 data update every 15 seconds
#

def new_btc38_client
  client = HTTPClient.new
  client.connect_timeout=5
  client.receive_timeout=5
  return client
end

def btc38_get (uri:nil)
  if uri.nil?
    return
  end
  client = new_btc38_client
  begin
    return client.get uri, nil, {"User-Agent":"curl/7.35.0","Accept":"*/*"}
  rescue Exception => e
    print "btc38_get error: "
    puts e
  end
end

def btc38_post (uri:nil, data:{})
  if uri.nil?
    return
  end
  client = new_btc38_client
  begin
    return client.post uri, data, {"User-Agent":"curl/7.35.0","Accept":"*/*"}
  rescue Exception => e
    print "btc38_post error: "
    puts e
  end
end

def fetch_btc38 (quote="bts", base="cny", max_orders=5)
  btc38_fetch quote:quote, base:base, max_orders:max_orders
end

def btc38_fetch (quote:"bts", base:"cny", max_orders:5)
  #http://api.btc38.com/v1/depth.php?c=ltc&mk_type=cny
  uri='http://api.btc38.com/v1/depth.php?c='+quote+'&mk_type='+base
  resp = btc38_get uri:uri
  #puts resp
  #puts JSON.pretty_generate resp
  if resp.nil?<commit_msg>add error log for btc38 get and post<commit_after>#!/usr/bin/env ruby

require "httpclient"
require "json"
require "digest"

require_relative "myfunc"
require_relative "config"
require_relative "mylogger"

####################################
# btc38 data update every 15 seconds
#

def new_btc38_client
  client = HTTPClient.new
  client.connect_timeout=5
  client.receive_timeout=5
  return client
end

def btc38_get (uri:nil)
  if uri.nil?
    return
  end
  client = new_btc38_client
  begin
    return client.get uri, nil, {"User-Agent":"curl/7.35.0","Accept":"*/*"}
  rescue Exception => e
    print "btc38_get error: "
    puts e
    $LOG.debug (method(__method__).name) { {"error"=>e} }
    return
  end
end

def btc38_post (uri:nil, data:{})
  if uri.nil?
    return
  end
  client = new_btc38_client
  begin
    return client.post uri, data, {"User-Agent":"curl/7.35.0","Accept":"*/*"}
  rescue Exception => e
    print "btc38_post error: "
    puts e
    $LOG.debug (method(__method__).name) { {"error"=>e} }
    return
  end
end

def fetch_btc38 (quote="bts", base="cny", max_orders=5)
  btc38_fetch quote:quote, base:base, max_orders:max_orders
end

def btc38_fetch (quote:"bts", base:"cny", max_orders:5)
  #http://api.btc38.com/v1/depth.php?c=ltc&mk_type=cny
  uri='http://api.btc38.com/v1/depth.php?c='+quote+'&mk_type='+base
  resp = btc38_get uri:uri
  #puts resp
  #puts JSON.pretty_generate resp
  if resp.nil?
{'fraction_non_alphanumeric': 0.16154131159688773, 'fraction_numerical': 0.033345683586513526, 'mean_word_length': 4.212355212355212, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2285639', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1033, 'n_words': 228}