-
Notifications
You must be signed in to change notification settings - Fork 29
/
Rakefile
120 lines (105 loc) · 3.76 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require 'rubygems'
require 'middleman-gh-pages'
require 'dotenv/tasks'
require 'yt'
require 'yaml'
require 'nokogiri'
require 'feed_validator'
class Helpers
def self.validate_feed(filename)
data = File.read(filename)
v = W3C::FeedValidator.new
raise "Invalid feed" unless v.validate_data(data)
raise "Invalid feed" unless v.valid
end
end
module Enumerable
def sorted?
each_cons(2).all? { |a, b| (a <=> b) <= 0 }
end
end
task :default => [:build, "lint:speakers", "lint:editions", "lint:feeds"]
task :fetchyt, [:user] => :dotenv do |t, args|
url = "https://www.youtube.com/user/#{args[:user]}/"
channel = Yt::Channel.new url: url
channel.videos.each do |video|
puts " - language: English"
puts " speakers: [TODO]"
puts " title: #{video.title}"
puts " tags: []"
puts " youtube: #{video.id}"
end
end
task :fetchwwdc, [:year] => :dotenv do |t, args|
yaml_content = open("https://raw.githubusercontent.com/ASCIIwwdc/wwdc-session-transcripts/master/#{args[:year]}/_sessions.yml"){|f| f.read}
yaml_data = YAML::load(yaml_content)
yaml_data.each do |id, video|
puts " - language: English"
puts " speakers: [TODO]"
puts " title: \"#{video[:title]}\""
puts " description: \"#{video[:description]}\""
puts " tags: [#{video[:track]}]".downcase
puts " wwdc: \"wwdc#{args[:year]}-#{id}\""
puts " direct-link: \"https://developer.apple.com/videos/play/wwdc#{args[:year]}-#{id}\""
end
end
task :fetchvimeo, [:channel] => :dotenv do |t, args|
doc = Nokogiri::XML(open("https://vimeo.com/channels/#{args[:channel]}/videos/rss"))
doc.css("item").each do |item|
description = Nokogiri::HTML(item.xpath("description").text)
puts " - language: English"
puts " speakers: [TODO]"
puts " title: #{item.css("title").text}"
# Only takes the first paragraph as description
puts " description: #{description.css("p")[2].text}"
puts " tags: []"
puts " vimeo: #{item.css("link").text.split("/").last}"
end
end
namespace :lint do
task :speakers do
videos = YAML.load_file('data/videos.yml')
speakers = YAML.load_file('data/speakers.yml')
all_speaker_names = videos.values.flatten.map { |video| video['speakers'] }.flatten.uniq
no_entry = all_speaker_names.reject{ |s| speakers[s] }
result = Hash.new
no_entry.each do |s|
result[s] = { "twitter" => "TODO" }
end
unless result.empty?
STDERR.puts "Please add entries for the following speakers:"
puts result.to_yaml
raise
end
end
task :editions do
videos = YAML.load_file('data/videos.yml')
data_editions = YAML.load_file('data/editions.yml')
data_events = YAML.load_file('data/events.yml')
# TODO: this is duplicated from the video_helpers.rb
editions = Hash.new
data_editions.each do |metadata|
editions["#{metadata["event"]} #{metadata["edition"]}"] = metadata
end
edition_dates = data_editions.map { |v| DateTime.parse(v['date']) }
raise "The editions.yml is not sorted by date." unless edition_dates.sorted?
no_events = editions.values.reject { |metadata|
data_events[metadata["event"]] != nil
}
unless no_events.empty?
raise "Missing entries in data/events.yml for the following events: \n#{no_events.join(", ")}"
end
no_editions = videos.keys.reject { |edition_name|
edition = editions[edition_name]
edition && edition['url'] != nil && edition['date'] != nil
# && edition['slug'] != nil
}
unless no_editions.empty?
raise "Missing entries in data/editions.yml for the following editions: \n#{no_editions.join(", ")}"
end
end
task :feeds => :build do
Helpers.validate_feed 'build/recent.xml'
Helpers.validate_feed 'build/twitterfeed.xml'
end
end