-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter-o-matic.rb
executable file
·64 lines (52 loc) · 1.66 KB
/
twitter-o-matic.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/local/bin/ruby
# -*- encoding: utf-8 -*-
#encoding=utf-8
require 'rubygems'
require 'open-uri'
require 'erb'
require 'sanitize'
require 'json'
require 'twitter'
require './secret_stuff'
def time_ago_in_words(from_time, include_seconds = false)
distance_of_time_in_words(from_time, Time.now, include_seconds)
end
def log(tag,message)
puts tag + ": " + message
end
@twitter_account = "team461wbi"
tweetz = Twitter.user_timeline(@twitter_account)
@tweets = []
tweetz.each do |twt|
text = twt.text
twt.urls.each do |url|
text.gsub!(url.url, "<a href=\"" + url.expanded_url + "\">" + url.display_url + "</a>")
end
twt.media.each do |media|
text.gsub!(media.url, "<a href=\"" + media.expanded_url + "\">" + media.display_url + "</a>")
end
twt.hashtags.each do |hashtag|
text.gsub!("#" + hashtag.text, "<a href=\"https://twitter.com/search/?q=%23" + hashtag.text + "\" target=\"_blank\">" + "#" + hashtag.text + "</a>")
end
@tweets << {:text => text, :info => "by @" + twt.from_user + ", on " + twt.created_at().iso8601.split("T")[0] + " at " + twt.created_at().iso8601.split("T")[1].split("-")[0].split(":")[0..1].join(":")}
end
begin
@template = ""
log("WRITE", "Reading the template")
File.open('./views/twitter-o-matic.html.erb', 'r') do |f|
@template = f.read
end
log("WRITE", "ERB-ifying the template")
template = ERB.new @template
log("WRITE", "Writing the file")
File.open("./public-twitter-o-matic/index.html", 'w') do |f|
f << template.result(binding)
end
rescue => variable
File.open('./error.log', 'a') do |f|
f << $!
log("WRITE", "ERROR: \"" + $!.to_s + "\"!")
print variable.backtrace.join("\n")
log("WRITE", "END ERROR")
end
end