Permalink
Browse files

Add badwords scaffold; and rake task to scrub the db

  • Loading branch information...
1 parent f8bae16 commit 2e2d78e08b17fe2776fef69461375ef56fe8fc43 @aditya aditya committed Apr 27, 2009
@@ -0,0 +1,85 @@
+class BadwordsController < ApplicationController
+ # GET /badwords
+ # GET /badwords.xml
+ def index
+ @badwords = Badword.find(:all)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @badwords }
+ end
+ end
+
+ # GET /badwords/1
+ # GET /badwords/1.xml
+ def show
+ @badword = Badword.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @badword }
+ end
+ end
+
+ # GET /badwords/new
+ # GET /badwords/new.xml
+ def new
+ @badword = Badword.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @badword }
+ end
+ end
+
+ # GET /badwords/1/edit
+ def edit
+ @badword = Badword.find(params[:id])
+ end
+
+ # POST /badwords
+ # POST /badwords.xml
+ def create
+ @badword = Badword.new(params[:badword])
+
+ respond_to do |format|
+ if @badword.save
+ flash[:notice] = 'Badword was successfully created.'
+ format.html { redirect_to(@badword) }
+ format.xml { render :xml => @badword, :status => :created, :location => @badword }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @badword.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /badwords/1
+ # PUT /badwords/1.xml
+ def update
+ @badword = Badword.find(params[:id])
+
+ respond_to do |format|
+ if @badword.update_attributes(params[:badword])
+ flash[:notice] = 'Badword was successfully updated.'
+ format.html { redirect_to(@badword) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @badword.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /badwords/1
+ # DELETE /badwords/1.xml
+ def destroy
+ @badword = Badword.find(params[:id])
+ @badword.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(badwords_url) }
+ format.xml { head :ok }
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module BadwordsHelper
+end
View
@@ -0,0 +1,3 @@
+class Badword < ActiveRecord::Base
+ set_table_name "blacklist"
+end
@@ -0,0 +1,12 @@
+<h1>Editing badword</h1>
+
+<% form_for(@badword) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.submit "Update" %>
+ </p>
+<% end %>
+
+<%= link_to 'Show', @badword %> |
+<%= link_to 'Back', badwords_path %>
@@ -0,0 +1,18 @@
+<h1>Listing badwords</h1>
+
+<table>
+ <tr>
+ </tr>
+
+<% for badword in @badwords %>
+ <tr>
+ <td><%= link_to 'Show', badword %></td>
+ <td><%= link_to 'Edit', edit_badword_path(badword) %></td>
+ <td><%= link_to 'Destroy', badword, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New badword', new_badword_path %>
@@ -0,0 +1,11 @@
+<h1>New badword</h1>
+
+<% form_for(@badword) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.submit "Create" %>
+ </p>
+<% end %>
+
+<%= link_to 'Back', badwords_path %>
@@ -0,0 +1,3 @@
+
+<%= link_to 'Edit', edit_badword_path(@badword) %> |
+<%= link_to 'Back', badwords_path %>
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>Badwords: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
View
@@ -0,0 +1,43 @@
+require 'curb'
+require 'nokogiri'
+
+namespace "sickcity" do
+
+ desc %{Clean noisy tweets}
+ task :clean_noisy_tweets => :environment do |t|
+ count = 0
+ Mention.find(:all, :conditions => 'message is NOT NULL').each do |m|
+ destroy = false
+ # Commenting out tweet-fetching code for now
+ #puts m
+ #tweet_id = m.link.split('/').last
+ #twitter_url = "http://twitter.com/statuses/show/#{tweet_id}.xml"
+ #puts twitter_url
+ #doc = Curl::Easy.perform(twitter_url)
+ #parsed_doc = Nokogiri.parse(doc.body_str)
+ #puts parsed_doc
+
+ #text = parsed_doc.search("text").inner_html
+ text = m.message
+ if text =~ /^RT\s/ || text =~ /http/ || text =~ /^\@/ || (text =~ /\s\#/ && !(text =~ /\s\#sickcity/))
+ destroy = true
+ end
+
+ if !destroy
+ Badword.all.each do |badword|
+ if text =~ /#{badword.term}/
+ destroy = true
+ puts "Matched: #{badword.term}"
+ puts "Deleting: #{m.message}"
+ end
+ break if destroy == true
+ end
+ end
+
+ count += 1 if destroy
+ # Not ready to scrub yet
+ # m.destroy if destroy
+ end
+ puts "Count: #{count}"
+ end
+end
@@ -0,0 +1,54 @@
+body { background-color: #fff; color: #333; }
+
+body, p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a { color: #000; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+.fieldWithErrors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#errorExplanation {
+ width: 400px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+
+#errorExplanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ background-color: #c00;
+ color: #fff;
+}
+
+#errorExplanation p {
+ color: #333;
+ margin-bottom: 0;
+ padding: 5px;
+}
+
+#errorExplanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
+
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class BadwordsControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:badwords)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create badword" do
+ assert_difference('Badword.count') do
+ post :create, :badword => { }
+ end
+
+ assert_redirected_to badword_path(assigns(:badword))
+ end
+
+ test "should show badword" do
+ get :show, :id => badwords(:one).id
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => badwords(:one).id
+ assert_response :success
+ end
+
+ test "should update badword" do
+ put :update, :id => badwords(:one).id, :badword => { }
+ assert_redirected_to badword_path(assigns(:badword))
+ end
+
+ test "should destroy badword" do
+ assert_difference('Badword.count', -1) do
+ delete :destroy, :id => badwords(:one).id
+ end
+
+ assert_redirected_to badwords_path
+ end
+end
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class BadwordTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end

0 comments on commit 2e2d78e

Please sign in to comment.