Last active
January 16, 2018 02:56
-
-
Save drench/65c58b4aa133f83781d8ad3280b4ca45 to your computer and use it in GitHub Desktop.
Given an array of tweet objects, this generates a CSV of frequency per hour. IOW: when is this user awake?
This file contains 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
#!/bin/sh | |
TZ=UTC jq -rc ' | |
.[] | | |
. + { | |
hour: .created_at | strptime("%a %b %d %T %z %Y")[3], | |
quoted_status: .quoted_status | |
} | | |
{ hour: .hour } + | |
if .retweeted_status|type == "object" then | |
{ kind: "retweet" } | |
elif .in_reply_to_status_id|type == "number" then | |
{ kind: "reply" } | |
elif .quoted_status == null then | |
{ kind: "tweet" } | |
else | |
{ kind: "quote_tweet" } | |
end | [.hour, .kind] | |
' | | |
ruby -e ' | |
require "json" | |
report = (0..23).map do |n| | |
[n, { tweet: 0, retweet: 0, quote_tweet: 0, reply: 0 }] | |
end.to_h | |
ARGF.each do |line| | |
hour, kind = JSON.parse(line) | |
report[hour][kind.to_sym] += 1 | |
end | |
puts "hour,tweets,retweets,quote_tweets,replies" | |
report.each do |hour, totals| | |
puts "#{hour},#{totals[:tweet]},#{totals[:retweet]},#{totals[:quote_tweet]},#{totals[:reply]}" | |
end | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment