Skip to content

Commit

Permalink
better logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vanakenm committed Dec 29, 2017
1 parent 5de2223 commit 736d2c4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion app/controllers/effin_quotes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
end

def logs
@logs = EffinLog.all
@logs = EffinLog.order(created_at: :desc)
end

def home; end
Expand Down
22 changes: 11 additions & 11 deletions app/models/effin_quote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ class EffinQuote < ApplicationRecord
include PgSearch
pg_search_scope :search_by_word, against: [:contents]

def complete?
url && twitter_url && contents
def self.find_by_word(word)
complete.search_by_word(word).first
end

def self.find_or_random(text)
quote = EffinQuote.find_by_word(text)
quote ? [quote, false] : [EffinQuote.complete.sample, true]
end

def self.complete
where('url is not null and twitter_url is not null and contents is not null')
end

def self.incomplete
where('url is null or twitter_url is null or contents is null')
end

def self.find_by_word(word)
complete.search_by_word(word).first
def complete?
url && twitter_url && contents
end

def self.find_or_random(text)
quote = EffinQuote.find_by_word(text)
quote ? [quote, false] : [EffinQuote.complete.sample, true]
def self.incomplete
where('url is null or twitter_url is null or contents is null')
end
end
2 changes: 2 additions & 0 deletions app/views/effin_quotes/logs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<th>team</th>
<th>quote</th>
<th>random</th>
<th>date</th>
</tr>
</thead>
<tbody>
Expand All @@ -18,6 +19,7 @@
<td><%= log.team_doman %></td>
<td><%= link_to log.effin_quote.contents, log.effin_quote %></td>
<td><%= log.random %></td>
<td><%= time_ago_in_words(log.created_at) %> ago</td>
</tr>
<% end %>
</tbody>
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
devise_for :users
root to: 'effin_quotes#home'

get 'commands/create'
get '/authorize', to: 'oauth#authorize'
get '/oauth/callback', to: 'oauth#authorize_callback'
get '/success', to: 'oauth#success'
Expand Down
14 changes: 5 additions & 9 deletions db/from_tweets.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV('TWITTER_CONSUMER_KEY')
config.consumer_key = ENV('TWITTER_CONSUMER_KEY')
config.consumer_secret = ENV('TWITTER_CONSUMER_SECRET')
config.access_token = ENV('TWITTER_ACCESS_TOKEN')
config.access_token_secret = ENV('TWITTER_ACCESS_TOKEN_SECRET')
Expand All @@ -8,18 +8,14 @@
tweets = client.get_all_tweets('effinbirds')

# Let's find the tweets that contains an image
raw = tweets.map do |t|
tweets.each do |t|
next unless t.media && t.media.first && t.media.first.uri
image_url = t.media.first.media_uri
tweet_url = t.uri

[image_url, tweet_url]
end.compact

raw.each do |r|
next if EffinQuote.find_by(url: r.first.to_s)

EffinQuote.create(url: r.first.to_s, twitter_url: r.second.to_s)
next if EffinQuote.find_by(url: image_url.to_s)

EffinQuote.create(url: image_url.to_s, twitter_url: tweet_url.to_s)
end

# From Twitter gem example of getting all tweets for a given account
Expand Down
36 changes: 18 additions & 18 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

# EffinQuote.create([
# {
# contents: "good luck with your bullshit",
# url: "https://pbs.twimg.com/media/DQ2tB-xWkAAKKJh.jpg"
# },
# {
# contents: "got it you're dim",
# url: "https://pbs.twimg.com/media/DQ117aPW4AEmnWF.jpg"
# },
# {
# contents: "where is your fucking brain",
# url: "https://pbs.twimg.com/media/DQxjO2fWsAEFIMd.jpg"
# },
# {
# contents: "I am not your fucking mom",
# url: "https://pbs.twimg.com/media/DQwsRAzXcAAIV-n.jpg"
# }
# ])
EffinQuote.create([
{
contents: "good luck with your bullshit",
url: "https://pbs.twimg.com/media/DQ2tB-xWkAAKKJh.jpg"
},
{
contents: "got it you're dim",
url: "https://pbs.twimg.com/media/DQ117aPW4AEmnWF.jpg"
},
{
contents: "where is your fucking brain",
url: "https://pbs.twimg.com/media/DQxjO2fWsAEFIMd.jpg"
},
{
contents: "I am not your fucking mom",
url: "https://pbs.twimg.com/media/DQwsRAzXcAAIV-n.jpg"
}
])

0 comments on commit 736d2c4

Please sign in to comment.