Skip to content
This repository was archived by the owner on Oct 22, 2019. It is now read-only.

Commit 9a55483

Browse files
committed
Updated to match new Sequel and Twitter gem APIs, added Procfile
1 parent 0c16f7f commit 9a55483

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: bundle exec rackup --port $PORT

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Run
22

3-
I've just updated to make it workable at all with newest versions of all gems and it just runs on:
4-
$ ruby application.rb
3+
I've just updated to make it workable at all with newest versions of all gems and it just runs via:
4+
$ bundle exec rackup
55

66
But the config.ru lets it deploy to Heroku as is
77

app.rb

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'rubygems'
22
require 'bundler'
3+
require 'sequel'
34
Bundler.require
45

56
# Database setup
@@ -32,30 +33,29 @@
3233
# get the max id from the database to pass to our search query
3334
since_id = tweets.max(:twitter_id)
3435
page = 1
36+
page_max = 20
37+
curses = %w{shit fuck cunt arse arsehole prick bastard fucking}
3538

3639
# load all the new tweets into the DB
3740
while true do
38-
@search = Twitter::Search.new('"tony abbott" shit OR fuck OR cunt OR arse OR arsehole OR prick OR bastard OR fucking')
41+
item_count = 0
3942
# 20 per page - twitter docs say 100, but seems to be less, so we
4043
# cover our bases for pagination. this pagination method also leaves
4144
# a small possibility of duplicates, but it's not a big deal.
42-
@search.per_page(20)
43-
@search.page(page)
44-
@search.since(since_id)
45-
item_count = 0
45+
options = {count: page_max, result_type: 'recent', since_id: since_id}
4646

47-
@search.each do |item|
48-
tweets.insert(:twitter_id => item["id"].to_i, :content => item["text"])
47+
twitter.search(%Q{"tony abbott" #{curses.join(" OR ")} -rt}, options).take(20).each do |item|
48+
tweets.insert(:twitter_id => item.id, :content => item.text)
4949
item_count = item_count + 1
5050
end
5151
# if we don't have more than 20 items, we can exit
52-
break if item_count < 20
52+
break if item_count < page_max
5353
page = page + 1
5454
end
5555

5656
@results = []
5757

58-
@all_results = tweets.order(:twitter_id.desc).each do |item|
58+
@all_results = tweets.order(:twitter_id).reverse.each do |item|
5959
# ignore items in the blacklist file or that start with rt/RT (retweets)
6060
unless BLACKLISTED_STRINGS.any? {|i| item[:content].downcase.match(i.downcase)} || item[:content].downcase.match(/^rt/)
6161
@results << '<p id="' + item[:id].to_s + '">' +
@@ -76,7 +76,6 @@
7676
haml :index, :options => {:format => :html4, :attr_wrapper => '"'}
7777
end
7878

79-
8079
# Configure Block.
8180
configure do
8281
BLACKLISTED_STRINGS = []
@@ -87,3 +86,14 @@
8786
end
8887
end
8988
end
89+
90+
def twitter
91+
@twitter ||= Twitter::REST::Client.new do |config|
92+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
93+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
94+
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
95+
config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
96+
end
97+
98+
@twitter
99+
end

config.ru

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require "rubygems"
21
require "sinatra"
32

43
root_dir = File.dirname(__FILE__)

0 commit comments

Comments
 (0)