Last active
February 11, 2020 22:22
-
-
Save tansengming/bc5e54d02534c0de35c8900bffd6e0ac to your computer and use it in GitHub Desktop.
Revisions
-
tansengming revised this gist
Feb 11, 2020 . 2 changed files with 15 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,15 @@ require 'irb' require 'pathname' require 'json' require 'rake/clean' require 'time' class Tweet attr_reader :tweet_id, :created_at def initialize(row) @tweet_id = row.dig('tweet', 'id') @created_at = Time.parse(row.dig('tweet', 'created_at')) @row = row end end @@ -78,9 +79,13 @@ end CLEAN.include 'daily/tweets-*.html' task :parse_json do tweet_path = Pathname.new('tweet.js') tweet_json = tweet_path.read[25..-1] tweets = JSON .parse(tweet_json) .map{ |row| Tweet.new(row) } mkdir_p 'daily' (1..12).each do |month| 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ - retrieve your twitter archive from https://twitter.com/settings/account - make sure `tweet.js` is in the same folder as the Rakefile - `rake clean && rake parse_json` - `open index.html` -
tansengming revised this gist
Mar 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ } var currentTime = new Date(); window.location = "daily/tweets-" + (currentTime.getMonth() + 1).pad() + "-" + currentTime.getDate().pad() + ".html" </script> </body> </html> -
tansengming revised this gist
Mar 5, 2017 . No changes.There are no files selected for viewing
-
tansengming revised this gist
Mar 5, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -47,6 +47,7 @@ class DayPage <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=480"> </head> <body> HEADEOF -
tansengming revised this gist
Mar 5, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ - retrieve your twitter archive from https://twitter.com/settings/account - make sure `tweets.csv` is in the same folder as the Rakefile - `rake clean && rake parse_csv` - `open index.html` -
tansengming revised this gist
Mar 5, 2017 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> Number.prototype.pad = function(size) { var s = String(this); while (s.length < (size || 2)) {s = "0" + s;} return s; } var currentTime = new Date(); window.location = "daily/tweets-" + currentTime.getMonth().pad() + "-" + currentTime.getDate().pad() + ".html" </script> </body> </html> -
tansengming revised this gist
Mar 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class DayPage def call header + tweets.map{|tweet| tweet.created_at.year}.uniq.sort.reverse.map do |year| [ "<h2>#{year}</h2>", tweets.select{|t| t.created_at.year == year }.map(&:tweet_id).map{|id| embed(id)} -
tansengming revised this gist
Mar 5, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -75,18 +75,19 @@ class DayPage end end CLEAN.include 'daily/tweets-*.html' task :parse_csv do file = 'tweets.csv' tweets = CSV.read(file, headers:true).map{|row| Tweet.new(row)} mkdir_p 'daily' (1..12).each do |month| (1..31).each do |day| tweets_on_this_day = tweets.select{|tweet| tweet.created_at.month == month && tweet.created_at.day == day}.sort_by(&:created_at) if tweets_on_this_day.any? tweet_filename = "daily/tweets-#{sprintf '%02d', month}-#{sprintf '%02d', day}.html" puts "Writing #{tweet_filename}..." open(tweet_filename, 'w') do |f| -
tansengming revised this gist
Mar 5, 2017 . 2 changed files with 3 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ - retrieve your twitter archive from https://twitter.com/settings/account - make sure `tweets.csv` is in the same folder as the Rakefile - `rake clean && rake parse_csv` -
tansengming created this gist
Mar 5, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,98 @@ require 'csv' require 'time' require 'rake/clean' require 'irb' class Tweet attr_reader :tweet_id, :created_at def initialize(row) @tweet_id = row['tweet_id'] @created_at = Time.parse(row['timestamp']) @row = row end end class DayPage attr_reader :tweets, :filename def self.call(tweets) new(tweets).call end def initialize(tweets) @tweets = tweets end def call header + tweets.map{|tweet| tweet.created_at.year}.uniq.sort.map do |year| [ "<h2>#{year}</h2>", tweets.select{|t| t.created_at.year == year }.map(&:tweet_id).map{|id| embed(id)} ] end.flatten.join("\n") + footer end def embed(id) str=<<~EMBEDEOF <blockquote class="twitter-tweet" data-lang="en"> <a href="https://twitter.com/sengming/status/#{id}"></a> </blockquote> EMBEDEOF end def header str=<<~HEADEOF <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> </head> <body> HEADEOF end def footer str=<<~FOOTEREOF <script>window.twttr = (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function(f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs"));</script> </body> FOOTEREOF end end CLEAN.include 'tweets-*.html' task :parse_csv do file = 'tweets.csv' tweets = CSV.read(file, headers:true).map{|row| Tweet.new(row)} (1..12).each do |month| (1..31).each do |day| tweets_on_this_day = tweets.select{|tweet| tweet.created_at.month == month && tweet.created_at.day == day}.sort_by(&:created_at) if tweets_on_this_day.any? tweet_filename = "tweets-#{sprintf '%02d', month}-#{sprintf '%02d', day}.html" puts "Writing #{tweet_filename}..." open(tweet_filename, 'w') do |f| f.write DayPage.(tweets_on_this_day) end end end end end