Last active
March 11, 2019 22:25
-
-
Save claymcleod/b3adc0a5ca47b716dd6b to your computer and use it in GitHub Desktop.
Simple ruby datamining example
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
# Title: Simple Ruby Datamining Example | |
# Authors: Clay McLeod | |
# Description: Mines data every minute concerning how many people are logged into a certain subreddit. | |
# Section: Ruby | |
# Subsection: Data Science | |
require 'csv' | |
require 'rubygems' | |
require 'nokogiri' | |
require 'rest-client' | |
while true | |
CSV.open("./data.csv", "ab") do |csv| | |
doc = Nokogiri::HTML(RestClient.get("http://www.reddit.com/r/destinythegame")) | |
text = doc.xpath('//html/body/div/div/div/p/span')[0].text | |
csv << [Time.now, text] | |
end | |
sleep 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works, but is an example of how code was usually written in Pascal or bare C, not how it should be written in Ruby.