Permalink
Browse files

UI tweaks.

  • Loading branch information...
1 parent 050a57e commit d99a045ab7e922aef838c5991fa3eac68af53467 @pwnall committed Jul 18, 2010
@@ -0,0 +1,84 @@
+class ScrapeOrdersController < ApplicationController
+ # GET /scrape_orders
+ # GET /scrape_orders.xml
+ def index
+ @scrape_orders = ScrapeOrder.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @scrape_orders }
+ end
+ end
+
+ # POST /scrape_orders/1/run
+ # POST /scrape_orders/1/run.xml
+ def run
+ @scrape_order = ScrapeOrder.find(params[:id])
+ @scrape_order.run
+
+ respond_to do |format|
+ format.html { redirect_to(scrape_orders_path, :notice => 'Scrape order was successfully ran.') }
+ format.xml { render :xml => @scrape_order }
+ end
+ end
+
+ # GET /scrape_orders/new
+ # GET /scrape_orders/new.xml
+ def new
+ @scrape_order = ScrapeOrder.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @scrape_order }
+ end
+ end
+
+ # GET /scrape_orders/1/edit
+ def edit
+ @scrape_order = ScrapeOrder.find(params[:id])
+ end
+
+ # POST /scrape_orders
+ # POST /scrape_orders.xml
+ def create
+ @scrape_order = ScrapeOrder.new(params[:scrape_order])
+
+ respond_to do |format|
+ if @scrape_order.save
+ format.html { redirect_to(scrape_orders_path, :notice => 'Scrape order was successfully created.') }
+ format.xml { render :xml => @scrape_order, :status => :created, :location => @scrape_order }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @scrape_order.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /scrape_orders/1
+ # PUT /scrape_orders/1.xml
+ def update
+ @scrape_order = ScrapeOrder.find(params[:id])
+
+ respond_to do |format|
+ if @scrape_order.update_attributes(params[:scrape_order])
+ format.html { redirect_to(scrape_orders_path, :notice => 'Scrape order was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @scrape_order.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /scrape_orders/1
+ # DELETE /scrape_orders/1.xml
+ def destroy
+ @scrape_order = ScrapeOrder.find(params[:id])
+ @scrape_order.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(scrape_orders_url) }
+ format.xml { head :ok }
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module ScrapeOrdersHelper
+end
@@ -7,14 +7,6 @@ def location=(new_location)
self.lat, self.lng = geocode[:lat], geocode[:lng]
end
- def geocode_location
- if location[-2, 2] == 'us'
- location
- else
- [location, city].join ' near '
- end
- end
-
def self.for_url(url)
where(:cl_url => url).first || new(:cl_url => url)
end
@@ -0,0 +1,8 @@
+class ScrapeOrder < ActiveRecord::Base
+ def run
+ starting_time = Time.now
+ ListingPopulator.new.run start_url, page_depth
+ self.last_ran_at = Time.now
+ self.last_runtime = last_ran_at - starting_time
+ end
+end
@@ -0,0 +1,18 @@
+<div class="search_result">
+ <div class="header">
+ <span class="price">$<%= listing.price %></span>
+ <span class="rooms"><%= pluralize listing.rooms, 'room' %></span>
+ <span class="location"><%= listing.location %></span>
+ </div>
+ <div class="description">
+ <%= listing.title %>
+ </div>
+ <div class="footer">
+ <span class="date"><%= listing.posted_at.strftime('%m/%d %H:%M') %></span>
+ <%= link_to listing.cl_url, listing.cl_url %>
+ </div>
+ <div class="actions">
+ <%= link_to 'Show', listing %>
+ <%= link_to 'Destroy', listing, :confirm => 'Are you sure?', :method => :delete %>
+ </div>
+</div>
@@ -1,28 +1,5 @@
<h1>Listings</h1>
-<table>
- <tr>
- <th>Price</th>
- <th>Rooms</th>
- <th>Location</th>
- <th>Title</th>
- <th>Posted at</th>
- <th>Url</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
<% @listings.each do |listing| %>
- <tr>
- <td><%= listing.price %></td>
- <td><%= listing.rooms %></td>
- <td><%= listing.location %></td>
- <td><%= listing.title %></td>
- <td><%= listing.posted_at.strftime('%m/%d %H:%M') %></td>
- <td><%= link_to listing.cl_url, listing.cl_url %></td>
- <td><%= link_to 'Show', listing %></td>
- <td><%= link_to 'Destroy', listing, :confirm => 'Are you sure?', :method => :delete %></td>
- </tr>
+<%= render 'listings/search_result', :listing => listing %>
<% end %>
-</table>
@@ -16,6 +16,16 @@
</p>
<p>
+ <b>City:</b>
+ <%= @listing.city %>
+</p>
+
+<p>
+ <b>Latitude, longitude:</b>
+ <%= @listing.lat %>, <%= @listing.lng %>
+</p>
+
+<p>
<b>Title:</b>
<%= @listing.title %>
</p>
@@ -26,8 +36,13 @@
</p>
<p>
- <b>Url:</b>
- <%= @listing.cl_url %>
+ <b>Original post:</b>
+ <%= link_to @listing.cl_url, @listing.cl_url %>
+</p>
+
+<p>
+ <b>Parser:</b>
+ <%= @listing.parser_hash %>
</p>
<%= link_to 'Back', listings_path %>
@@ -0,0 +1,25 @@
+<%= form_for(@scrape_order) do |f| %>
+ <% if @scrape_order.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@scrape_order.errors.count, "error") %> prohibited this scrape_order from being saved:</h2>
+
+ <ul>
+ <% @scrape_order.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :start_url %><br />
+ <%= f.text_field :start_url %>
+ </div>
+ <div class="field">
+ <%= f.label :page_depth %><br />
+ <%= f.text_field :page_depth %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing scrape_order</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @scrape_order %> |
+<%= link_to 'Back', scrape_orders_path %>
@@ -0,0 +1,30 @@
+<h1>Scrape Orders</h1>
+
+<table>
+ <tr>
+ <th>Start url</th>
+ <th>Page depth</th>
+ <th>Last ran at</th>
+ <th>Completion time</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @scrape_orders.each do |scrape_order| %>
+ <tr>
+ <td><%= scrape_order.start_url %></td>
+ <td><%= scrape_order.page_depth %></td>
+ <td><%= scrape_order.ran_last_at ?
+ scrape_order.ran_last_at.strftime('%m/%d %H:%M') : 'never' %></td>
+ <td><%= scrape_order.last_runtime %></td>
+ <td><%= link_to 'Run', run_scrape_order_path(scrape_order), :method => :post %></td>
+ <td><%= link_to 'Edit', edit_scrape_order_path(scrape_order) %></td>
+ <td><%= link_to 'Destroy', scrape_order, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Scrape order', new_scrape_order_path %>
@@ -0,0 +1,5 @@
+<h1>New scrape_order</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', scrape_orders_path %>
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Start url:</b>
+ <%= @scrape_order.start_url %>
+</p>
+
+<p>
+ <b>Page depth:</b>
+ <%= @scrape_order.page_depth %>
+</p>
+
+
+<%= link_to 'Edit', edit_scrape_order_path(@scrape_order) %> |
+<%= link_to 'Back', scrape_orders_path %>
View
@@ -1,4 +1,8 @@
Clh::Application.routes.draw do
+ resources :scrape_orders do
+ member { post :run }
+ end
+
resources :geocode_fetches
resources :page_fetches
@@ -1,15 +1,19 @@
class CreateListings < ActiveRecord::Migration
def self.up
create_table :listings do |t|
+ t.string :cl_url, :limit => 128, :null => false
+
t.integer :price, :null => false
t.integer :rooms, :null => false
- t.datetime :posted_at, :null => false
- t.string :cl_url, :limit => 128, :null => false
t.string :title, :limit => 128, :null => false
+ t.datetime :posted_at, :null => false
+
t.string :location, :limit => 128, :null => false
t.string :city, :limit => 32, :null => false
t.decimal :lat, :precision => 14, :scale => 10, :null => false
t.decimal :lng, :precision => 14, :scale => 10, :null => false
+
+ t.string :parser_hash, :limit => 64, :null => false
end
add_index :listings, :cl_url, :unique => true, :null => false
end
@@ -0,0 +1,15 @@
+class CreateScrapeOrders < ActiveRecord::Migration
+ def self.up
+ create_table :scrape_orders do |t|
+ t.string :start_url, :limit => 128, :null => false
+ t.integer :page_depth, :null => false
+ t.datetime :ran_last_at, :null => true
+ t.float :last_runtime, :null => true
+ end
+ add_index :scrape_orders, :start_url, :unique => true, :null => false
+ end
+
+ def self.down
+ drop_table :scrape_orders
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100717075712) do
+ActiveRecord::Schema.define(:version => 20100718005836) do
create_table "geocode_fetches", :force => true do |t|
t.string "location", :limit => 128, :null => false
@@ -23,15 +23,16 @@
add_index "geocode_fetches", ["location", "city"], :name => "index_geocode_fetches_on_location_and_city", :unique => true
create_table "listings", :force => true do |t|
- t.integer "price", :null => false
- t.integer "rooms", :null => false
- t.datetime "posted_at", :null => false
- t.string "cl_url", :limit => 128, :null => false
- t.string "title", :limit => 128, :null => false
- t.string "location", :limit => 128, :null => false
- t.string "city", :limit => 32, :null => false
- t.decimal "lat", :precision => 14, :scale => 10, :null => false
- t.decimal "lng", :precision => 14, :scale => 10, :null => false
+ t.string "cl_url", :limit => 128, :null => false
+ t.integer "price", :null => false
+ t.integer "rooms", :null => false
+ t.string "title", :limit => 128, :null => false
+ t.datetime "posted_at", :null => false
+ t.string "location", :limit => 128, :null => false
+ t.string "city", :limit => 32, :null => false
+ t.decimal "lat", :precision => 14, :scale => 10, :null => false
+ t.decimal "lng", :precision => 14, :scale => 10, :null => false
+ t.string "parser_hash", :limit => 64, :null => false
end
add_index "listings", ["cl_url"], :name => "index_listings_on_cl_url", :unique => true
@@ -44,4 +45,13 @@
add_index "page_fetches", ["url"], :name => "index_page_fetches_on_url", :unique => true
+ create_table "scrape_orders", :force => true do |t|
+ t.string "start_url", :limit => 128, :null => false
+ t.integer "page_depth", :null => false
+ t.datetime "ran_last_at"
+ t.float "last_runtime"
+ end
+
+ add_index "scrape_orders", ["start_url"], :name => "index_scrape_orders_on_start_url", :unique => true
+
end
Oops, something went wrong.

0 comments on commit d99a045

Please sign in to comment.