Skip to content

Instantly share code, notes, and snippets.

@fields
Created November 18, 2013 18:51
Show Gist options
  • Save fields/7533194 to your computer and use it in GitHub Desktop.
Save fields/7533194 to your computer and use it in GitHub Desktop.
speedtest_mongo.rb
#!/usr/bin/env ruby
require 'yajl'
require 'mongo'
speedtest_json = `/path/to/speedtest-cli --json`
begin
if speedtest_json.nil? or speedtest_json == ""
raise Yajl::ParseError
end
speedtest_hash = Yajl::Parser.parse(speedtest_json)
speedtest_hash['timestamp'] = Time.now
puts speedtest_json
mongo = Mongo::MongoClient.new("localhost")
db = mongo['speedtest']
collection = db['results_' + Time.now.strftime("%Y%m")]
collection.insert(speedtest_hash)
rescue Yajl::ParseError => e
puts "failed to load json"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment