From ac1d175ed56311ec87f7a2cda036408311dac874 Mon Sep 17 00:00:00 2001
From: Martin Van Aken
Date: Sat, 10 Feb 2018 11:32:17 +0100
Subject: [PATCH] status
---
app/controllers/effin_quotes_controller.rb | 8 ++++++--
app/models/effin_quote.rb | 4 ++++
app/views/effin_quotes/home.html.erb | 10 ++++++----
app/views/effin_quotes/status.html.erb | 18 ++++++++++++++++++
config/database.yml | 2 +-
config/routes.rb | 2 ++
db/from_tweets.rb | 14 +++++++-------
7 files changed, 44 insertions(+), 14 deletions(-)
create mode 100644 app/views/effin_quotes/status.html.erb
diff --git a/app/controllers/effin_quotes_controller.rb b/app/controllers/effin_quotes_controller.rb
index 25bf3f0..0acac35 100644
--- a/app/controllers/effin_quotes_controller.rb
+++ b/app/controllers/effin_quotes_controller.rb
@@ -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
@@ -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
@@ -49,5 +53,5 @@ def destroy
def quote_params
params.require(:effin_quote).permit(:contents)
- end
+ end
end
diff --git a/app/models/effin_quote.rb b/app/models/effin_quote.rb
index 64dedd9..be77cfb 100644
--- a/app/models/effin_quote.rb
+++ b/app/models/effin_quote.rb
@@ -17,6 +17,10 @@ def self.words
words
end
+ def self.everywords
+ complete.map(&:words).flatten
+ end
+
def words
contents.split(" ")
end
diff --git a/app/views/effin_quotes/home.html.erb b/app/views/effin_quotes/home.html.erb
index 9c91415..72b0b2b 100644
--- a/app/views/effin_quotes/home.html.erb
+++ b/app/views/effin_quotes/home.html.erb
@@ -12,10 +12,12 @@
Typing
/effin help
will get you a short explanation. If you lack inspiration, just type /effin words
and some random words will be proposed.
-Thanks to Aaron Reynolds for creating Effin' Birds and allowing me to create this and to Joe for outstanding support.
-
-Created by Martin - let me know if you find any problem
+Thanks to Aaron Reynolds for creating Effin' Birds and allowing me to create this and to Joe for outstanding support ◦ created by Martin - let me know if you find any problem ◦ current <%= link_to "status", "/status" %>
Lacking ideas? Here are some words from the birds:
-<%= image_tag("cloud.png") %>
\ No newline at end of file
+<%= image_tag("cloud.png") %>
+
+
+(courtesy of https://www.wordclouds.com/)
+
\ No newline at end of file
diff --git a/app/views/effin_quotes/status.html.erb b/app/views/effin_quotes/status.html.erb
new file mode 100644
index 0000000..56cee19
--- /dev/null
+++ b/app/views/effin_quotes/status.html.erb
@@ -0,0 +1,18 @@
+Effin' bot status
+
+
+
+A Slack bot that allows you to answer to coworkers using supportive messages right from the effin' birds mouths
+
+Last generated quotes
+
+
+ <% @last_quotes.each do |log| %>
+
+
+ "<%= log.text %>"
+
+ <%= image_tag(log.effin_quote.url, class: "img-responsive") %>
+
+ <% end %>
+
diff --git a/config/database.yml b/config/database.yml
index 0e85e79..e5bdc22 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -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`.
diff --git a/config/routes.rb b/config/routes.rb
index e49b03c..59d4f9f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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'
diff --git a/db/from_tweets.rb b/db/from_tweets.rb
index 2feeb35..8557291 100644
--- a/db/from_tweets.rb
+++ b/db/from_tweets.rb
@@ -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
@@ -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?