Twitter scripts/layouts, Twitter import
This commit is contained in:
parent
65a6a20708
commit
bc62533852
12 changed files with 480 additions and 1 deletions
46
lib/twitter.rb
Normal file
46
lib/twitter.rb
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# encoding: utf-8
|
||||
|
||||
module Nanoc::DataSources::Contrib
|
||||
|
||||
# Fetch data from downloaded twitter csv file
|
||||
class Twitter < Nanoc::DataSource
|
||||
identifier :twitter_file
|
||||
|
||||
def items
|
||||
@items ||= begin
|
||||
require 'csv'
|
||||
|
||||
if @site.config[:twitter_file].nil?
|
||||
raise Nanoc::Errors::GenericTrivial.new('Cannot read Twitter data: site configuration has no twitter_file')
|
||||
end
|
||||
|
||||
# Get data
|
||||
if ! File.exists?(@site.config[:twitter_file])
|
||||
return []
|
||||
end
|
||||
|
||||
# Convert to items
|
||||
@items = []
|
||||
CSV.foreach(@site.config[:twitter_file]) do |row|
|
||||
# Get data
|
||||
content = row[3]
|
||||
attributes = {
|
||||
:kind => 'twitter',
|
||||
:id => row[0],
|
||||
:date => Time.parse(row[1]),
|
||||
:nick => row[2],
|
||||
:url => "https://twitter.com/#{row[2]}/status/#{row[0]}"
|
||||
}
|
||||
identifier = "/_twitter/#{row[0]}/"
|
||||
mtime = Time.parse(row[1])
|
||||
|
||||
# Build item
|
||||
@items += [ Nanoc::Item.new(content, attributes, identifier, mtime) ]
|
||||
end
|
||||
@items
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue