Skip to content

Commit

Permalink
status
Browse files Browse the repository at this point in the history
  • Loading branch information
vanakenm committed Feb 10, 2018
1 parent d11b9a1 commit ac1d175
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
8 changes: 6 additions & 2 deletions app/controllers/effin_quotes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class EffinQuotesController < ApplicationController
before_action :authenticate_user!, except: :home
before_action :authenticate_user!, except: [:home, :status]

def index
@quotes = EffinQuote.all
Expand All @@ -23,6 +23,10 @@ def show
@count = EffinQuote.incomplete.count
end

def status
@last_quotes = EffinLog.where(random: false).order(created_at: :desc).limit(12)
end

def incomplete
@quotes = EffinQuote.incomplete

Expand All @@ -49,5 +53,5 @@ def destroy

def quote_params
params.require(:effin_quote).permit(:contents)
end
end
end
4 changes: 4 additions & 0 deletions app/models/effin_quote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def self.words
words
end

def self.everywords
complete.map(&:words).flatten
end

def words
contents.split(" ")
end
Expand Down
10 changes: 6 additions & 4 deletions app/views/effin_quotes/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

<p>Typing <pre>/effin help</pre> will get you a short explanation. If you lack inspiration, just type <pre>/effin words</pre> and some random words will be proposed.</p>

<p>Thanks to <a href="https://twitter.com/aaronreynolds" target="_blank">Aaron Reynolds</a> for creating Effin' Birds and allowing me to create this and to <a href="https://twitter.com/Boejurt">Joe</a> for outstanding support.</p>

<p>Created by <a href="https://twitter.com/martinvanaken">Martin</a> - let me know if you find any problem</p>
<p>Thanks to <a href="https://twitter.com/aaronreynolds" target="_blank">Aaron Reynolds</a> for creating Effin' Birds and allowing me to create this and to <a href="https://twitter.com/Boejurt">Joe</a> for outstanding support &#9702; created by <a href="https://twitter.com/martinvanaken">Martin</a> - let me know if you find any problem &#9702; current <%= link_to "status", "/status" %></p>

<p>Lacking ideas? Here are some words from the birds:</p>

<%= image_tag("cloud.png") %>
<%= image_tag("cloud.png") %>

<p>
(courtesy of https://www.wordclouds.com/)
</p>
18 changes: 18 additions & 0 deletions app/views/effin_quotes/status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1>Effin' bot status</h1>

<a href="https://github.com/vanakenm/effinbot"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/82b228a3648bf44fc1163ef44c62fcc60081495e/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png"></a>

<p>A Slack bot that allows you to answer to coworkers using supportive messages right from the <a href="https://twitter.com/effinbirds">effin' birds</a> mouths</p>

<h2>Last generated quotes</h2>

<div class="row">
<% @last_quotes.each do |log| %>
<div class="col-xs-4">
<h4 class="text-center">
"<%= log.text %>"
</h4>
<%= image_tag(log.effin_quote.url, class: "img-responsive") %>
</div>
<% end %>
</div>
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ default: &default

development:
<<: *default
database: effin_dv
database: effinprod

# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
devise_for :users
root to: 'effin_quotes#home'

get '/status', to: 'effin_quotes#status'

get '/authorize', to: 'oauth#authorize'
get '/oauth/callback', to: 'oauth#authorize_callback'
get '/success', to: 'oauth#success'
Expand Down
14 changes: 7 additions & 7 deletions db/from_tweets.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
client = Twitter::REST::Client.new do |config|
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')
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']
end

tweets = client.get_all_tweets('effinbirds')
tweets = client.get_all_tweets('effinbirds', nil)

# Let's find the tweets that contains an image
tweets.each do |t|
tweets.select { |t| t.created_at > 35.days.ago }.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
Expand All @@ -25,7 +25,7 @@ def collect_with_max_id(collection = [], max_id = nil, &block)
response.empty? ? collection.flatten : collect_with_max_id(collection, response.last.id - 1, &block)
end

def client.get_all_tweets(user)
def client.get_all_tweets(user, date)
collect_with_max_id do |max_id|
options = { count: 200, include_rts: true }
options[:max_id] = max_id unless max_id.nil?
Expand Down

0 comments on commit ac1d175

Please sign in to comment.