This commit is contained in:
simplefl 2015-07-18 12:47:57 +02:00
commit 38edef1bb9
9 changed files with 50 additions and 108 deletions

View file

@ -1,29 +0,0 @@
require 'rss/2.0'
require 'open-uri'
class TweetsController < ApplicationController
def index
@tweets = Tweet.all order: "created_at DESC"
@nobody = true
end
def show
@tweet = Tweet.find(params[:id])
end
def refresh
open('http://twitter.com/statuses/user_timeline/16676427.rss') do |http|
RSS::Parser.parse(http.read, false).items.each do |item|
unless Tweet.first :conditions => {:link => item.link}
tweet = Tweet.new
tweet.link = item.link
tweet.msg = item.title.gsub(/NS2: /, "")
tweet.created_at = DateTime.parse item.pubDate.to_s
tweet.save
end
end
end
render text: t(:tweets_refresh)
end
end

View file

@ -171,8 +171,26 @@ module ApplicationHelper
end
end
def nsltv_regex
/\[NSLTV\]/i
end
def upcoming_matches
GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset).upcoming.sort_by do |event|
GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset).
upcoming.
find_all{|e|
not nsltv_regex =~ (e.summary)
}.sort_by do |event|
event.start
end
end
def upcoming_nsltv
GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset).
upcoming.
find_all{|e|
nsltv_regex =~ (e.summary)
}.sort_by do |event|
event.start
end
end

View file

@ -1,22 +0,0 @@
# == Schema Information
#
# Table name: tweets
#
# id :integer not null, primary key
# msg :string(255)
# link :string(255)
# created_at :datetime
# updated_at :datetime
#
class Tweet < ActiveRecord::Base
include Extra
scope :recent2, :order => "created_at DESC", :limit => 2
scope :recent, :order => "created_at DESC", :limit => 5
has_many :comments, :as => :commentable
def to_s
msg
end
end

View file

@ -1,12 +0,0 @@
<% @tweets.each do |item| %>
<div class="box wide">
<h3>
<%= link_to (longtime item.created_at), item.link %>
</h3>
<p>
<%= raw h item.msg %>
</p>
<%= link_to "Comments: #{item.comments.count}", item %>
</div>
<% end %>

View file

@ -1,14 +0,0 @@
<h1>
NS2 Feed
</h1>
<div class="box wide">
<h3>
<%= link_to (longtime @tweet.created_at), @tweet.link %>
</h3>
<p>
<%= h @tweet.msg %>
</p>
</div>
<%= add_comments @tweet %>

View file

@ -2,7 +2,7 @@
<div class="widget calendar">
<h4><%= t('widget.schedule') %></h4>
<div class="widget-content-wrapper">
<div class="widget-content-wrapper">
<% upcoming_matches.group_by{ |e| e.start.month }.each do |month, events| %>
<% events.group_by { |e| e.start.day }.each do |day, day_events| %>
<div class="separator"><%= day_events.first.start.strftime("%A, %e %B") %></div>
@ -19,3 +19,24 @@
</div>
</div>
<% end %>
<% if upcoming_nsltv.size > 0 %>
<div class="widget calendar">
<h4>NSLTV</h4>
<div class="widget-content-wrapper">
<% upcoming_nsltv.group_by{ |e| e.start.month }.each do |month, events| %>
<% events.group_by { |e| e.start.day }.each do |day, day_events| %>
<div class="separator"><%= day_events.first.start.strftime("%A, %e %B") %></div>
<% day_events.each do |event| %>
<div class="entry">
<p class="summary">
<span class="time"><%= event.start.strftime("%H:%M %Z") %></span>
<%= event.formatted_summary.sub(nsltv_regex, '') %>
</p>
</div>
<% end %>
<% end %>
<% end %>
</div>
</div>
<% end %>

View file

@ -1,19 +0,0 @@
<div class="header">Latest NS2 tweets</div>
<div class="body">
<div class="content">
<h3>
Latest tweets
</h3>
<ul>
<ol>
<% Tweet.recent.each do |tweet| %>
<li>
<%= namelink tweet, 25 %>
</li>
<% end %>
</ol>
</ul>
</div>
</div>
<%= link_to "More..", articles_path %>

View file

@ -0,0 +1,8 @@
class RemoveTweets < ActiveRecord::Migration
def up
drop_table :tweets
end
def down
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150621212615) do
ActiveRecord::Schema.define(:version => 20150701233306) do
create_table "article_versions", :force => true do |t|
t.integer "article_id"
@ -715,15 +715,6 @@ ActiveRecord::Schema.define(:version => 20150621212615) do
add_index "topics", ["forum_id"], :name => "index_topics_on_forum_id"
add_index "topics", ["user_id"], :name => "index_topics_on_user_id"
create_table "tweets", :force => true do |t|
t.string "msg"
t.string "link"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "tweets", ["created_at"], :name => "index_tweets_on_created_at"
create_table "user_versions", :force => true do |t|
t.integer "user_id"
t.integer "version"