<commit_before>#!/usr/bin/env ruby
require 'net/http'
require 'openssl'

ts = Time.now.to_i

speedtest_result_io = IO.popen("/usr/local/bin/speedtest-cli --simple")
ping = speedtest_result_io.gets[/Ping: (\d*.+\d*) ms/, 1]
dl = speedtest_result_io.gets[/Download: (\d*.+\d*) Mbit\/s/, 1]
ul = speedtest_result_io.gets[/Upload: (\d*.+\d*) Mbit\/s/, 1]
key = "123456"

puts "Ts: #{ts}, ping: #{ping}, dl: #{dl}, ul: #{ul}"

uri = URI('https://www.example.com/speed-test/api/submit.php')

if uri.path.empty?
  uri.path = "/"
end

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == "https")

begin
  response = http.request_post(uri.path, "timestamp=#{ts}&ping=#{ping}&dl=#{dl}&ul=#{ul}&key=#{key}")
  p response
  puts response.body
rescue Exception => e
  puts "Cannot send result to server"
  puts e.message
end<commit_msg>cron script can now read secret key and URL values from env.<commit_after>#!/usr/bin/env ruby
require 'net/http'
require 'openssl'

ts = Time.now.to_i

speedtest_result_io = IO.popen("/usr/local/bin/speedtest-cli --simple")
ping = speedtest_result_io.gets[/Ping: (\d*.+\d*) ms/, 1]
dl = speedtest_result_io.gets[/Download: (\d*.+\d*) Mbit\/s/, 1]
ul = speedtest_result_io.gets[/Upload: (\d*.+\d*) Mbit\/s/, 1]
key = "123456"

unless ENV["SPEED_MONITOR_SECRET_KEY"].nil?
  key = ENV["SPEED_MONITOR_SECRET_KEY"]
else
  key = "123456"
end

unless ENV["SPEED_MONITOR_URL"].nil?
  uri = URI(ENV["SPEED_MONITOR_URL"])
else
  uri = URI('https://www.example.com/speed-test/api/submit.php')
end

puts "Ts: #{ts}, ping: #{ping}, dl: #{dl}, ul: #{ul}"

if uri.path.empty?
  uri.path = "/"
end

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == "https")

begin
  response = http.request_post(uri.path, "timestamp=#{ts}&ping=#{ping}&dl=#{dl}&ul=#{ul}&key=#{key}")
  p response
  puts response.body
rescue Exception => e
  puts "Cannot send result to server"
  puts e.message
end
{'fraction_non_alphanumeric': 0.2053941908713693, 'fraction_numerical': 0.012448132780082987, 'mean_word_length': 4.373259052924791, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4348272', 'n_tokens_mistral': 800, 'n_tokens_neox': 771, 'n_words': 164}