Skip to content

Instantly share code, notes, and snippets.

@ainame
Created December 31, 2011 14:57
Show Gist options
  • Select an option

  • Save ainame/1544211 to your computer and use it in GitHub Desktop.

Select an option

Save ainame/1544211 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'active_support/time'
require 'json'
require 'scanf'
require 'net/http'
require 'nkf'
require_relative './csv.rb'
require 'pp'
# "147908914338480128","111217 142007","府中二郎の小ラーメン全部(豚・温泉玉子・チーズ)入りの食券 http://t.co/RMh2BDwP"
year = 2011
path = ARGV[0]
$count = 0
$last_count_date = Date.new(2010)
$day_count = 0
$eat_count = 0
$url_regxp = Regexp.new("(http:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)")
$jiro_regxp = Regexp.new("二郎|マシ|小豚")
data = []
KCSV.foreach(path) do |row|
date = Date.parse(row[1])
if date.year == year
data << [date, row[2]]
else
break
end
end
puts "read done."
# sub routine
def parse(tweet)
if $url_regxp =~ tweet[1]
uri = $1
if /(http:\/\/t\.co.*)/ =~ tweet[1]
uri = Net::HTTP.get_response(URI.parse(uri))["Location"]
begin
tweet[1].sub!(/(http:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/, uri)
rescue
pp "Error:" + uri.to_s
end
end
if $jiro_regxp =~ tweet[1]
$eat_count += 1
$count += 1
if $last_count_date != tweet[0]
$day_count += 1
$last_count_date = tweet[0]
end
puts tweet[0].to_s + ":" + tweet[1].to_s
end
end
end
def compare_date(a, b)
return a.year == b.year && a.month == b.month && a.day == b.day
end
date = Date.new(2011)
day = 0
data.each do |tweet|
parse(tweet)
date = date.since(day.days).to_date
end
puts "合計:#{data.length}"
puts "「二郎」:#{$count}, #{$day_count}, #{$eat_count}回, #{($count*100/data.length)}%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment