<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>db/migrate/20090403023001_add_asciicasts_to_episodes.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -37,6 +37,11 @@
         &lt;/div&gt;
       &lt;% end %&gt;
     &lt;/div&gt;
+    &lt;% if episode.asciicasts? %&gt;
+      &lt;div class=&quot;asciicasts&quot;&gt;
+        &lt;%= link_to &quot;Read it on ASCIIcasts&quot;, &quot;http://asciicasts.com/episodes/#{episode.to_param}&quot; %&gt;
+      &lt;/div&gt;
+    &lt;% end %&gt;
     &lt;%= yield if block_given? %&gt;
   &lt;/div&gt;
 &lt;/div&gt;</diff>
      <filename>app/views/episodes/_episode.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -25,6 +25,10 @@
       &lt;%= f.label :duration, 'Duration' %&gt;&lt;br /&gt;
       &lt;%= f.text_field :duration %&gt;
     &lt;/p&gt;
+    &lt;p&gt;
+      &lt;%= f.check_box :asciicasts %&gt;
+      &lt;%= f.label :asciicasts, &quot;Available on ASCIIcasts&quot; %&gt;
+    &lt;/p&gt;
     &lt;% for download in @episode.downloads %&gt;
       &lt;% fields_for_download(download) do |d| %&gt;
         &lt;%= error_messages_for :download, :object =&gt; download %&gt;</diff>
      <filename>app/views/episodes/_form.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version =&gt; 20090318164300) do
+ActiveRecord::Schema.define(:version =&gt; 20090403023001) do
 
   create_table &quot;comments&quot;, :force =&gt; true do |t|
     t.integer  &quot;episode_id&quot;
@@ -47,8 +47,9 @@ ActiveRecord::Schema.define(:version =&gt; 20090318164300) do
     t.datetime &quot;created_at&quot;
     t.datetime &quot;updated_at&quot;
     t.integer  &quot;position&quot;,       :default =&gt; 0
-    t.integer  &quot;comments_count&quot;, :default =&gt; 0, :null =&gt; false
+    t.integer  &quot;comments_count&quot;, :default =&gt; 0,     :null =&gt; false
     t.integer  &quot;seconds&quot;
+    t.boolean  &quot;asciicasts&quot;,     :default =&gt; false, :null =&gt; false
   end
 
   create_table &quot;spam_reports&quot;, :force =&gt; true do |t|</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,73 +1,9 @@
-namespace :legacy do
-  desc &quot;Migrate database from old railscasts site&quot;
-  task :migrate =&gt; :environment do
-    require 'mysql'
-    $db = Mysql.connect('localhost', 'root', ENV['DBPW'], 'railscasts_legacy')
-    
-    puts &quot;starting episodes&quot;
-    migrate_model Episode, 'episodes' do |row|
-      notes = row[:notes] || ''
-      notes.gsub!(/&lt;code lang=&quot;(.+)&quot;&gt;/, '@@@ \1')
-      notes.gsub!(&quot;&lt;/code&gt;&quot;, &quot;@@@&quot;)
-      row.slice(:id, :name, :published_at, :position, :description, :permalink).merge(:notes =&gt; notes)
-    end
-    
-    puts &quot;starting tags&quot;
-    migrate_model Tag, 'tags' do |row|
-      row
-    end
-    
-    puts &quot;starting taggings&quot;
-    migrate_model Tagging, 'episodes_tags' do |row|
-      row
-    end
-    
-    puts &quot;starting downloads&quot;
-    migrate_model Download, 'episodes' do |row|
-      min, sec = *row[:duration].split(':').map(&amp;:to_i)
-      seconds = min*60 + sec
-      [
-        {
-          :episode_id =&gt; row[:id],
-          :format =&gt; 'mov',
-          :url =&gt; &quot;http://media.railscasts.com/videos/#{row[:file_name]}.mov&quot;,
-          :seconds =&gt; seconds,
-          :bytes =&gt; row[:file_size]
-        },
-        {
-          :episode_id =&gt; row[:id],
-          :format =&gt; 'm4v',
-          :url =&gt; &quot;http://media.railscasts.com/ipod_videos/#{row[:file_name]}.m4v&quot;,
-          :seconds =&gt; seconds,
-          :bytes =&gt; row[:ipod_file_size]
-        }
-      ]
-    end
-    
-    puts &quot;starting comments&quot;
-    migrate_model Comment, &quot;comments WHERE approved='1' AND id NOT IN (39396, 39422)&quot; do |row|
-      row.except(:approved)
-    end
-  end
-  
-  def migrate_model(model_class, table_name)
-    model_class.delete_all
-    rows = $db.query(&quot;SELECT * FROM #{table_name}&quot;)
-    rows.each_hash do |row|
-      insert_row(model_class, yield(row.symbolize_keys))
-    end
-  end
-  
-  def insert_row(model_class, row)
-    if row.kind_of? Array
-      row.each { |r| insert_row(model_class, r) }
-    else
-      record = model_class.new
-      row.each do |name, value|
-        value = Time.parse(value) + 7.hours if name.to_s =~ /_at$/ # convert times to UTC
-        record.write_attribute(name, value)
-      end
-      record.save(false) # skips validation
-    end
+desc &quot;Check if ASCIIcasts are available for episodes.&quot;
+task :asciicasts =&gt; :environment do
+  require 'thinking_sphinx' # for some reason this isn't being loaded in the environment
+  Episode.all(:conditions =&gt; { :asciicasts =&gt; false }, :limit =&gt; 5).each do |episode|
+    response = Net::HTTP.get_response(URI.parse(&quot;http://asciicasts.com/episodes/#{episode.position}&quot;))
+    episode.update_attribute(:asciicasts, true) if response.code == &quot;200&quot;
+    sleep 3 # so we don't hammer the server
   end
 end</diff>
      <filename>lib/tasks/application.rake</filename>
    </modified>
    <modified>
      <diff>@@ -189,6 +189,11 @@ ul {
   color: #666;
 }
 
+.episode .asciicasts {
+  margin-top: 6px;
+  font-size: 11px;
+}
+
 .episode .notes {
   font-size: 11px;
   margin-top: 10px;</diff>
      <filename>public/stylesheets/application.css</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7fc6dc54334087a0f3fdb01a6a93f83207563cbc</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Bates</name>
    <email>ryan@railscasts.com</email>
  </author>
  <url>http://github.com/ryanb/railscasts/commit/01e030a9ee77514aba4169ad212ce2dc6a400321</url>
  <id>01e030a9ee77514aba4169ad212ce2dc6a400321</id>
  <committed-date>2009-04-02T19:47:25-07:00</committed-date>
  <authored-date>2009-04-02T19:47:25-07:00</authored-date>
  <message>adding asciicasts to episode along with a rake task to check for new asciicasts episodes</message>
  <tree>fcaf00d58deb8c6046179e84ce2ea9c36deae35b</tree>
  <committer>
    <name>Ryan Bates</name>
    <email>ryan@railscasts.com</email>
  </committer>
</commit>
